Special RegExp

Z

Zarkan

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
 
R

RobG

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)
);
 
Z

Zarkan

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)
);

Thankssss!
That works fine!!

Zark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top