Special RegExp

Discussion in 'Javascript' started by Zarkan, Feb 1, 2007.

  1. Zarkan

    Zarkan Guest

    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
     
    Zarkan, Feb 1, 2007
    #1
    1. Advertising

  2. Zarkan

    RobG Guest

    On Feb 1, 4:34 pm, "Zarkan" <> 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
     
    RobG, Feb 1, 2007
    #2
    1. Advertising

  3. Zarkan

    Zarkan Guest

    On Jan 31, 11:30 pm, "RobG" <> wrote:
    > On Feb 1, 4:34 pm, "Zarkan" <> 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
     
    Zarkan, Feb 1, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin DeMello

    special characters within [] in a regexp

    Martin DeMello, Aug 15, 2006, in forum: Ruby
    Replies:
    2
    Views:
    74
    Martin DeMello
    Aug 15, 2006
  2. Joao Silva
    Replies:
    16
    Views:
    363
    7stud --
    Aug 21, 2009
  3. david.karr
    Replies:
    3
    Views:
    139
    david.karr
    Jun 6, 2006
  4. arno

    RegExp and special caracters

    arno, Feb 4, 2006, in forum: Javascript
    Replies:
    7
    Views:
    142
    Dr John Stockton
    Feb 7, 2006
  5. Gabriela
    Replies:
    4
    Views:
    547
    Tim Greer
    Dec 22, 2008
Loading...

Share This Page