Berkeley CSUA MOTD:Entry 28917
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2003/7/3-5 [Computer/SW/Languages/Perl] UID:28917 Activity:moderate
7/3     Stupid Regex question. I am trying to print if the line contains $word:
                print if /[^a-zA-Z]?$word[^a-zA-Z]/;'
        this won't work if the word is the last word on the line. i can't see
        a nice way to do that... what am i trying to accomplish? trying to
        teach someone regexp and show them how things can be more complicated
        than they seem and that
                print if /$word/
        is not sufficient.
        \_ print if /\b${word}\b/
           \_ ahhhhhhhhh. nice.
           \_ The braces aren't necessary. -geordan
              \_ but a semicolon is while we're being pedantic
                 \_ I figured that he was smart enough to figure out the
                    semicolon.  I couldn't remember if the {} were necessary so
                    I put them in.  I hoped he'd read the docs to find out what
                    \b was and all the other goodness there.  Why didn't you
                    answer the original question instead of nitpicking my
                    response?
                    \_ 1) because I didn't care to, and 2) he really
                          could've (and should've) looked in the perl book
                          for 2 minutes and it would've been obvious.