in reply to Help with matching .org

Essentially you are searching for something that is delimited either by whitespaces or by end of string/line, right?

In this case your regexp should look something like this:

# custom word boundary: my $wb = qr{ ^ | $ | \s }x; # you have to take care if you are checking for a left or a right word + boundary: if ($str =~ m/(?<=$wb)$termstr1(?=$wb)/){ ... }

Replies are listed 'Best First'.
Re^2: Help with matching .org
by bestresearch2 (Novice) on Jan 09, 2008 at 15:11 UTC
    Thanks! Delimited by whitespace, end of string/line, or beginning of string/line. Will this work for that too?
      hmmm. Perl does not like variable length lookaround. But it seems I can get away with (the less efficient):
      m/(^|?|\s)string(^|?|\s)/
      Thanks for your help!!!
        Perl does not like variable length lookaround.

        It doesn't like variable length look-behinds but variable length look-aheads are ok. You can get around the limitation by specifying an alternation of different length look-behinds, for example

        if ( $str =~ m{ (?: (?<=\A) | (?<=XXX) ) \d+ }x ) { ... }

        i.e do something if we find one or more digits preceded by either the beginning of the string or three 'X's. Note that I use the 'x' pattern modifier to allow whitespace and comments inside the pattern to aid readability.

        I hope this is of use.

        Cheers,

        JohnGG