in reply to Space or end of string in regex
You are almost there:
if( $line =~ m[^REM $sTest ?$]i ) { # ... }
The $ means end-of-line. The ? following the space preceding the $, means the space is optional.
More formally, zero or one spaces may exist here.
That said, allowing for just one trailing space is unusually mean. More normal would be to allow only whitespace to follow the required text before the end-of-line. Which could be written:
if( $line =~ m[^REM $sTest\s*$]i ) { # ... }
Formally zero or more whitespace characters may precede the end-of-line.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Space or end of string in regex
by davies (Monsignor) on Feb 02, 2012 at 23:00 UTC | |
by BrowserUk (Patriarch) on Feb 02, 2012 at 23:15 UTC | |
by Marshall (Canon) on Feb 03, 2012 at 20:47 UTC |