Using underscores as well as word boundaries to demarcate a pattern

Discussion in 'Perl' started by Laura, Jun 2, 2004.

  1. Laura

    Laura Guest

    I am using regular expressions to preprocess text and add text around
    certain terms. Because the text can contain html, I use look-ahead
    logic to exclude any text that comes between a "<" and a ">". My
    expression looks like this:

    (\\b)(term)(\\b)(?![^<]*>)

    Where "term" is the term I'm looking for in the text. It's working
    just fine, but now a new requirement has arisen that means we want to
    look for terms separated by underscores as well as word boundary
    characters.

    How can I modify the above pattern to find my terms when they're
    separated by either word boundary characters or an underscore?

    Any help gratefully accepted!
    Laura, Jun 2, 2004
    #1
    1. Advertising

  2. Laura

    Laura Guest

    I figured it out! Just needed to say \b|_ to get it to work, thusly:

    (\b|_)(term)(\b|_)(?![^<]*>)
    Laura, Jun 3, 2004
    #2
    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. J. Hall
    Replies:
    4
    Views:
    1,115
    J. Hall
    Jun 3, 2004
  2. Phrogz
    Replies:
    2
    Views:
    124
    William James
    Feb 19, 2005
  3. jmb-d

    redefining word boundaries?

    jmb-d, Jun 17, 2007, in forum: Ruby
    Replies:
    3
    Views:
    107
    jmb-d
    Jun 18, 2007
  4. Adam Akhtar
    Replies:
    4
    Views:
    176
    Adam Akhtar
    Aug 28, 2008
  5. Jeff
    Replies:
    6
    Views:
    126
    Colin Bartlett
    Jan 22, 2010
Loading...

Share This Page