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. Advertisements

  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. Advertisements

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,377
    J. Hall
    Jun 3, 2004
  2. Andy Glew
    Replies:
    84
    Views:
    2,446
    Dave Vandervies
    Oct 28, 2003
  3. Kari Laitinen

    Opinions about underscores in names

    Kari Laitinen, Nov 13, 2003, in forum: C++
    Replies:
    2
    Views:
    525
    Ekkehard Morgenstern
    Nov 13, 2003
  4. BRIAN VICKERY

    underscores in class member names

    BRIAN VICKERY, Jan 30, 2004, in forum: C++
    Replies:
    22
    Views:
    892
    Rolf Magnus
    Feb 1, 2004
  5. Phrogz
    Replies:
    2
    Views:
    207
    William James
    Feb 19, 2005
  6. jmb-d

    redefining word boundaries?

    jmb-d, Jun 17, 2007, in forum: Ruby
    Replies:
    3
    Views:
    167
    jmb-d
    Jun 18, 2007
  7. Adam Akhtar
    Replies:
    4
    Views:
    269
    Adam Akhtar
    Aug 28, 2008
  8. Jeff
    Replies:
    6
    Views:
    217
    Colin Bartlett
    Jan 22, 2010
Loading...