Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Special RegExp

Reply
Thread Tools

Special RegExp

 
 
Zarkan
Guest
Posts: n/a
 
      02-01-2007
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

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      02-01-2007
On Feb 1, 4:34 pm, "Zarkan" <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
 
Zarkan
Guest
Posts: n/a
 
      02-01-2007
On Jan 31, 11:30 pm, "RobG" <(E-Mail Removed)> wrote:
> On Feb 1, 4:34 pm, "Zarkan" <(E-Mail Removed)> wrote:
>
>
>
> > 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

 
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
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Special Report: How special are you? Death from Above MCSE 2 03-19-2007 07:22 PM
special characters within [] in a regexp Martin DeMello Ruby 2 08-15-2006 03:23 PM
How to "quote" all regexp expression special characters? david.karr Perl Misc 3 06-06-2006 06:27 PM
Special editions and Deluxe special edition dvd question. Rclrk43 DVD Video 8 12-29-2004 07:32 PM



Advertisments