Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > regular expressions -- very basic grouping question

Reply
Thread Tools

regular expressions -- very basic grouping question

 
 
Tom
Guest
Posts: n/a
 
      11-15-2006
[abc] - matches "a", "b", or "c"
[^abc] - matches anything except "a", "b", and "c"
(abc) - matches "abc", with back reference
??? - matches anything except "abc" literally?? What is the syntax for
this expression?

If this kind of non-matching grouping expression doesn't exist, what's
an alternate way to have the regexp engine (perl in my case), match
"anything but 'abc'"?

Thanks!

 
Reply With Quote
 
 
 
 
Tom
Guest
Posts: n/a
 
      11-15-2006
don't know why I wrote perl -- javascript obviously. working on too
many things at once!

Tom wrote:
> [abc] - matches "a", "b", or "c"
> [^abc] - matches anything except "a", "b", and "c"
> (abc) - matches "abc", with back reference
> ??? - matches anything except "abc" literally?? What is the syntax for
> this expression?
>
> If this kind of non-matching grouping expression doesn't exist, what's
> an alternate way to have the regexp engine (perl in my case), match
> "anything but 'abc'"?
>
> Thanks!


 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      11-16-2006
Tom said the following on 11/15/2006 2:21 PM:
> [abc] - matches "a", "b", or "c"
> [^abc] - matches anything except "a", "b", and "c"
> (abc) - matches "abc", with back reference
> ??? - matches anything except "abc" literally?? What is the syntax for
> this expression?
>
> If this kind of non-matching grouping expression doesn't exist, what's
> an alternate way to have the regexp engine (perl in my case), match
> "anything but 'abc'"?


There is probably a RegEx that will do it, but, if all you want is a
match for abc then you can test with indexOf and if it is present or not
then act accordingly.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
Julian Turner
Guest
Posts: n/a
 
      11-16-2006

Tom wrote:

[snip]
> [abc] - matches "a", "b", or "c"
> [^abc] - matches anything except "a", "b", and "c"
> (abc) - matches "abc", with back reference
> ??? - matches anything except "abc" literally?? What is the syntax for
> this expression?

[/snip]

Hi

Your question is ambiguous. Do you mean (a) you only want to accept a
string as a whole if it does not contain "abc", or (b) you only want
your pattern to accept an "a" if it is not followed by "bc", but it
does not matter if "abc" appears somewhere else?

If the answer is (a), then as already noted, you could use indexOf
instead.

If the answer is (b), then one way is to use a negative lookahead.

To quote from Microsoft's JScript documentation:-

(?!pattern)
"Negative lookahead matches the search string at any point where a
string not matching pattern begins. This is a non-capturing match, that
is, the match is not captured for possible later use. For example
'Windows (?!95|98|NT|2000)' matches "Windows" in "Windows 3.1" but does
not match "Windows" in "Windows 2000". Lookaheads do not consume
characters, that is, after a match occurs, the search for the next
match begins immediately following the last match, not after the
characters that comprised the lookahead."

Example:-

var re = /a(?!bc)/gi
var s = "adefgiabc";
alert(re.exec(s).length);

alerts 1, not 2.

Note that (?!pattern) is not supported by some older IE browsers.

Regards

Julian Turner

 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      11-16-2006
In message <(E-Mail Removed) om>, Wed,
15 Nov 2006 11:21:09, Tom <(E-Mail Removed)> writes
>[abc] - matches "a", "b", or "c"
>[^abc] - matches anything except "a", "b", and "c"
>(abc) - matches "abc", with back reference
>??? - matches anything except "abc" literally?? What is the syntax for
>this expression?
>
>If this kind of non-matching grouping expression doesn't exist, what's
>an alternate way to have the regexp engine (perl in my case), match
>"anything but 'abc'"?


I am using a standards-compliant newsreader. Your posting agent does
horrible things to your layout, as shown when viewing your article in my
reader; however, in reply mode I get the material quoted as presumably
intended. Please change your /modus operandi/ appropriately.

[abc] matches any character in the set "abc".
[^abc] matches any character not in the set "abc".

One approach to your problem, which should work even in older
RegExp-capable browsers, would be to use .replace(/abc/g, "\u0416"),
where \u0416 is a character which is known not to appear in the original
string, and you can then use [^\u0416] to be not matched.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      11-16-2006
Dr J R Stockton said the following on 11/16/2006 9:29 AM:
> In message <(E-Mail Removed) om>, Wed,
> 15 Nov 2006 11:21:09, Tom <(E-Mail Removed)> writes
>> [abc] - matches "a", "b", or "c"
>> [^abc] - matches anything except "a", "b", and "c"
>> (abc) - matches "abc", with back reference
>> ??? - matches anything except "abc" literally?? What is the syntax for
>> this expression?
>>
>> If this kind of non-matching grouping expression doesn't exist, what's
>> an alternate way to have the regexp engine (perl in my case), match
>> "anything but 'abc'"?

>
> I am using a standards-compliant newsreader. Your posting agent does
> horrible things to your layout, as shown when viewing your article in my
> reader; however, in reply mode I get the material quoted as presumably
> intended. Please change your /modus operandi/ appropriately.


Sounds like it is something with your newsreader. I have read the
original using three different newsreaders and none of them screw up the
layout.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
very very basic question aghazalp Python 6 04-02-2006 09:35 PM
Basic Regular Expressions question... Will Perl Misc 15 04-11-2005 08:54 AM
Very very very basic question Peter C Programming 14 02-14-2005 09:46 AM
nested grouping with regular expressions ds2000 Python 2 05-24-2004 03:24 PM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM



Advertisments