By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,806 Members | 1,341 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,806 IT Pros & Developers. It's quick & easy.

Special RegExp

P: n/a
Hi all,
I've got a question for you, Regular Expression Masters ;)

I'm not very experienced in that, but I've made many attempts and I
couldn't get the right regExp yet..

Basically, I need a regular expression able to find a certain string
(say, "abc") which is NOT followed by an HTML tag (that is, which is
not followed by "<").

I've tried with this:
/abc[^<]/

...But this actually does something different:
it finds "abc" when *followed by a character* which is different from
"<".

But I want to find the string when it's followed:
a) either by NOTHING
b) or by a character different from "<"

Then, I tried this (in order to find "abc" + no character, OR 1
character different from "<"):
/abc[^<]{0,1}/

...But this expression doesn't work either (that is, it matches the
string also when it's followed by "<")!

I've tried many other ways, but with no success!!
How shall I do??

Many thanks,
Zark

Feb 1 '07 #1
Share this Question
Share on Google+
2 Replies

P: n/a
On Feb 1, 4:34 pm, "Zarkan" <zar...@email.itwrote:
Hi all,
I've got a question for you, Regular Expression Masters ;)

I'm not very experienced in that, but I've made many attempts and I
couldn't get the right regExp yet..

Basically, I need a regular expression able to find a certain string
(say, "abc") which is NOT followed by an HTML tag (that is, which is
not followed by "<").

I've tried with this:
/abc[^<]/

..But this actually does something different:
it finds "abc" when *followed by a character* which is different from
"<".

But I want to find the string when it's followed:
a) either by NOTHING
b) or by a character different from "<"

Then, I tried this (in order to find "abc" + no character, OR 1
character different from "<"):
/abc[^<]{0,1}/

..But this expression doesn't work either (that is, it matches the
string also when it's followed by "<")!

I've tried many other ways, but with no success!!
How shall I do??
var a = 'abc';
var b = 'abc<';
var c = 'abcd';
var re = /abc([^<]|$)/;
alert(
a + ': ' + re.test(a) + '\n' +
b + ': ' + re.test(b) + '\n' +
c + ': ' + re.test(c)
);
--
Rob

Feb 1 '07 #2

P: n/a
On Jan 31, 11:30 pm, "RobG" <r...@iinet.net.auwrote:
On Feb 1, 4:34 pm, "Zarkan" <zar...@email.itwrote:
Hi all,
I've got a question for you, Regular Expression Masters ;)
I'm not very experienced in that, but I've made many attempts and I
couldn't get the right regExp yet..
Basically, I need a regular expression able to find a certain string
(say, "abc") which is NOT followed by an HTML tag (that is, which is
not followed by "<").
I've tried with this:
/abc[^<]/
..But this actually does something different:
it finds "abc" when *followed by a character* which is different from
"<".
But I want to find the string when it's followed:
a) either by NOTHING
b) or by a character different from "<"
Then, I tried this (in order to find "abc" + no character, OR 1
character different from "<"):
/abc[^<]{0,1}/
..But this expression doesn't work either (that is, it matches the
string also when it's followed by "<")!
I've tried many other ways, but with no success!!
How shall I do??

var a = 'abc';
var b = 'abc<';
var c = 'abcd';
var re = /abc([^<]|$)/;
alert(
a + ': ' + re.test(a) + '\n' +
b + ': ' + re.test(b) + '\n' +
c + ': ' + re.test(c)
);

--
Rob
Thankssss!
That works fine!!

Zark

Feb 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.