D
Dan Rawson
I'm attempting to extract a single word from a line which looks like:
TARGET = file1 file2 file3 .....
I need 'file1' from this line. Using:
s/.*?\=\s*([a-zA-Z_\.0-9]+).*/$1/ (Note the "+" following the char. class)
works fine as long as file1 is present. However, if I have a line which ends after the "=" sign, it returns the entire
line, instead of an empty string.
If I change the pattern to:
s/.*?\=\s*([a-zA-Z_\.0-9]*).*/$1/ (Note the "*" following the char. class)
it works; I get 'file1' back if it's there, and an empty string if not.
Questions:
1. My understanding was that the "+" would cause it to match one or more of the char. class (which would make it a
legal file name in this case). Why does it return the entire line if there's no match??
2. Why does the second pattern work differently than the first one if there's nothing after the "=" sign?
TIA . . . .
Dan
TARGET = file1 file2 file3 .....
I need 'file1' from this line. Using:
s/.*?\=\s*([a-zA-Z_\.0-9]+).*/$1/ (Note the "+" following the char. class)
works fine as long as file1 is present. However, if I have a line which ends after the "=" sign, it returns the entire
line, instead of an empty string.
If I change the pattern to:
s/.*?\=\s*([a-zA-Z_\.0-9]*).*/$1/ (Note the "*" following the char. class)
it works; I get 'file1' back if it's there, and an empty string if not.
Questions:
1. My understanding was that the "+" would cause it to match one or more of the char. class (which would make it a
legal file name in this case). Why does it return the entire line if there's no match??
2. Why does the second pattern work differently than the first one if there's nothing after the "=" sign?
TIA . . . .
Dan