473,382 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Regexp - negative match for fixed string (vs. a char list)?

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
Mar 28 '07 #1
4 3786
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.

Mar 28 '07 #2
On Mar 28, 11:07 am, "Noah Sussman" <blink...@gmail.comwrote:
var myMatch = myString.replace('blah', '');
of course I meant

var myMatch = myString.replace(/blah/g, '');

Mar 28 '07 #3
"Noah Sussman" <bl******@gmail.comwrote in message
news:11**********************@p15g2000hsd.googlegr oups.com...
On Mar 28, 11:07 am, "Noah Sussman" <blink...@gmail.comwrote:
>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
Mar 28 '07 #4
In comp.lang.javascript message <eu*******************@news.demon.co.uk>
, Wed, 28 Mar 2007 13:01:36, Mark Anderson <ma**@notmeyeardley.demon.co.
ukposted:
>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.

--
(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.zipTimo Salmi's Turbo Pascal FAQ.
Mar 30 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Piet | last post by:
Hello, I have a very strange problem with regular expressions. The problem consists of analyzing the properties of columns of a MySQL database. When I request the column type, I get back a string...
5
by: Cc | last post by:
hi, how do I pass fixed string byref to a dll . I had try <VBFixedString(10)> but when I run I keep getting system.accessviolation Any help would be great
3
by: Zach | last post by:
Hello, This might be a rather basic question, but I've tried a few things and I can't really find a solution as elegant as what I'd like for this problem. The situation is this - I have a file...
1
by: TDK02 | last post by:
Hi, I need someones help to Convert C++ strings to a C-style string (char*) in VC++ 6.0. What I need to do is something as follows. There is a string as, string sh = “hello”;
3
by: c676228 | last post by:
Hi everyone, I just realized that it's so important to validate each string, I mean 'each' before you insert data from asp page into database. I guess some customers just copy data from some...
2
by: juanefren | last post by:
How can I convert a string to a char list? for example "hello" -- I have been searching but I can't find my answers thanks --
3
by: Paddy | last post by:
Lets say i have a generator running that generates successive characters of a 'string' characters then I would have to 'freeze' the generator and pass the characters so far to re.search. It is...
20
by: arnimavidyarthy | last post by:
Hi, Hi, I am taking a string as an input from the user and it should only contain the chars:L , M or R I tried the folllowing in kodos but they are still not perfect:
2
by: Jimmy45 | last post by:
Hello, I am trying to convert a string into list of strings. The output is like the following: , , ]. However, the output must be like: My code is like the following:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.