
November 6th, 2008, 10:56 AM
|
|
|
|
S/(.*)/$1 something/gi; "double dipping"
I have some user variables (a high-level user with knowledge of regex and admin privileges, so it doesn't need to be sanitized) going into a substitution which is equivalent to:
Code:
$i = "TEST";
$i =~ s/(.*)/$1 Blah/gi;
print $i;
And it outputs: (it's doing it twice) Ok, so I know that the issue is the global. The problem is that sometimes I would want the same code to handle something like:
Code:
$i = "TEST THING is the BEST THING";
$i =~ s/(.*?) THING/$1 Blah/gi;
print $i;
which it correctly outputs:
Quote: | TEST Blah is the BEST Blah | Do I have to make some sort of conditional testing for the veracity of the wildcard with different multiple substitution syntaxes (or additional variable input allowing the user to turn on/off the global flag, which is what I'll probably end up doing), or is there a simpler way?
Thanks
__________________
If you can read this, I'm probably very confused and disorientated.
|