Is there a way in a regexp to *not* match a fixed string value?
Using [^blah] gives matches to anything not containing *any* of letters
b,l,a and h. Whereas I want to match anything that does not containing
the exact string 'blah', i.e. *all* the letters.
Possible?
Thanks
Mark
Noah Sussman - 28 Mar 2007 16:07 GMT
On Mar 28, 8:01 am, "Mark Anderson" <m...@notmeyeardley.demon.co.uk>
wrote:
> I want to match anything that does not containing
> the exact string 'blah', i.e. *all* the letters.
var myString = "sometimes blah is blah";
var myMatch = myString.replace('blah', '');
Now myMatch contains your original string, except for the parts that
matched "blah."
If that doesn't solve your problem, please provide example code that
includes the regex you are trying to fix, and an example of the kind
of string you want to process.
Noah Sussman - 28 Mar 2007 16:10 GMT
> var myMatch = myString.replace('blah', '');
of course I meant
var myMatch = myString.replace(/blah/g, '');
Mark Anderson - 28 Mar 2007 18:13 GMT
>> var myMatch = myString.replace('blah', '');
>
> of course I meant
>
> var myMatch = myString.replace(/blah/g, '');
Thanks, though it doesn't quite work for what I want...
var myString = "the road to blah is long"
var myMatch = myString.replace(/blah/g, '');
alert(myMatch);
myString = "the road to there is long"
var myMatch = myString.replace(/blah/g, '');
alert(myMatch);
// which is a match?
...but you got me thinking down a new line. In Perl you can set a var =
!regexp to flip the match. So, I can iterate an array of matches and in
the loop look for :
// 'myArray' holds the target strings
// myRe holds the regexp
for (1=0;i<myArray.length;i=i+1) {
if (!re.test(myArray[i]) { //
//do stuff
or for a fixed string just...
// 'myArray' holds the target strings
for (1=0;i<myArray.length;i=i+1) {
if (myArray[i] !== 'blah') { //
//do stuff
My mistake was to try and construct a 'negative' test rather than look
for the failure of a positive one.
Thanks for the nudge!
Mark
Dr J R Stockton - 30 Mar 2007 23:19 GMT
In comp.lang.javascript message <eudlet$9je$1$8302bc10@news.demon.co.uk>
, Wed, 28 Mar 2007 13:01:36, Mark Anderson <mark@notmeyeardley.demon.co.
uk> posted:
>Is there a way in a regexp to *not* match a fixed string value?
There's probably something better if you program only for more recent
browsers. But you can always do a global replace of the fixed string by
a peculiar character - \u263C occurs rarely in English text - then do a
not-match on that character, then substitute back.

Signature
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.