in reply to Weird Regex in CGI::Cookie
I know that Lincoln is pretty aggressive about stamping bugs out of his modules.
The problem you're seeing is that the regexp engine is acting lazy. The following regexp seems to work for your test strings:
s/\s*\b(.+)\b\s*/$1/
But it's probably better to anchor the regexp to the start and end of string, to draw it out to match the entire string. Even then it still just is a slightly ambiguous way to do things; to rely on greed outweighing non-greed. Especially when there are better ways to do it.
It is faster and more reliable to do it this way:
s/^\s+//; s/\s+$//;
Alternation could be used along with the /g modifier, but then you slow things down just a little.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Weird Regex in CGI::Cookie
by graff (Chancellor) on Oct 16, 2003 at 02:30 UTC |