473,465 Members | 4,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

regular expressions -- very basic grouping question

Tom
[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!

Nov 15 '06 #1
5 1319
Tom
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!
Nov 15 '06 #2
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/
Nov 15 '06 #3

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

Nov 16 '06 #4
In message <11*********************@m7g2000cwm.googlegroups.c om>, Wed,
15 Nov 2006 11:21:09, Tom <bi****@gmail.comwrites
>[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.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 16 '06 #5
Dr J R Stockton said the following on 11/16/2006 9:29 AM:
In message <11*********************@m7g2000cwm.googlegroups.c om>, Wed,
15 Nov 2006 11:21:09, Tom <bi****@gmail.comwrites
>[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/
Nov 16 '06 #6

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

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Tom | last post by:
I have struggled with the issue of whether or not to use Regular Expressions for a long time now, and after implementing many text manipulating solutions both ways, I've found that writing...
3
by: Gopinath | last post by:
Hi JavaScript Gurus, I've a question on Regular Expressions using RegExp object. I just want to know whether it is possible to do the search (see below) using RegExp. Any pointers would be of...
2
by: lltaylor | last post by:
Hello All, I am writing a regex scanning app, I want to allow the user to be able to enter multiple regular expressions. Is there a way I can search for all the regular expressions in one...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
6
by: Ludwig | last post by:
Hi, i'm using the regular expression \b\w to find the beginning of a word, in my C# application. If the word is 'public', for example, it works. However, if the word is '<public', it does not...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.