Perl Pattern Matching Question
I'm fairly new to perl and I'm having a slight pattern matching issue.
The problem piece of code looks something like this: until ($variable =~ /word/i) { do things} My problem is that as long as "word" is present the until function ignores whatever comes before word. I'd like to fix this. I had the same problem with characters which came after "word", and I fixed that by doing something like this: until (($variable =~ /word/i) and ($variable !~ /word./) and ($variable !~ /word./)){ do things} This works fine for characters after "word", but I can't seem to get the check to work for characters that appear before "word". Any help is appreciated. |
what exactly are you trying to match?
if you want to match strings that say "word" exactly, then you can use /^word$/ (this use is unnecessary as "lc($variable) eq 'word' " will do). ^ asserts the beginning of the line, and $ asserts the end. if you want to match strings where "word" is surrounded by whitespace or boundary of string, you can use /\bword\b/ (\b asserts word boundary) you can also construct more complicated assertions |
Thank you very much for your help. /^word$/ was sufficient. I was trying to match different things, as I was having the problem with all my programs. Most irritating were a few programs I wrote for my girlfriend. One of which would check for our names, and she kept inserting obnoxiously things before my name and laughing. It had to be stopped. Thanks again.
|
All times are GMT -5. The time now is 08:10 PM. |