in reply to Re^2: RegExp to Search All Array Members?
in thread RegExp to Search All Array Members?

I have tried to get this working, but have been unsuccessful. I am a noob to programming and perl so patience would be appreciated.

The search NEVER matches. I made sure the case is exactly the same in the doc and still no luck

Here is the code

#!/usr/bin/perl -w use strict; use warnings; open(FH, "Wachterpdf2txt.txt") or die "We have a problem: $!"; my @invoiceSearch = ("phone", "hunt", "dial", "tone", "static", "18d", + "system", "voice", "numbers", "voicemail", "MLX201", "programming", +"extension", "processor", "block", "mls", "programmed", "rollover", " +extension", "partner", "crosstalk", "merlin", "ringing"); my $regexStr="^static\\s+\\w+\\s+(" . (join "|",map quotemeta,@invoice +Search) . ")\\W.*"; print "$regexStr\n\n"; my $regexStr_rr = qr{$regexStr}i; # or "cloister" the 'i' in $regexStr while(<FH>) { chomp; my ( $hit ) = $_ =~ /$regexStr_rr/; if ($hit) { print "Beatle method \"$hit\" found on this line: $_\n"; } else { print "No Beatle method found on this line: $_\n"; } }

What I can't seem to find anywhere is what the ^static statement means in the Regex variable. I am pulling in a text document that was converted from .pdf I have stripped out all spaces and most punctuation. The text document looks fine to me.

Any help would be appreciated!

Replies are listed 'Best First'.
Re^4: RegExp to Search All Array Members?
by Anonymous Monk on Aug 16, 2012 at 20:42 UTC
    A bit late, but...

    ^ is a special character in regex that makes it find the match at the beginning of the string. So with '^static', it will find any string that begins with 'static'.

    So, it would match:
    static bool fred(...)

    But it wouldn't match
    stat bool fred(...)

    since static isn't at the very beginning of it, stat is.