David Gilden wrote:
Why am I getting 'one two three' in $s and not just 'one'
You might want to print $1, this will give you a better idea. $1 is being set to everything in the parentheses, which is everything you match, and the substituion only replaces the first matched portion of the string with the contents of $1, it leaves the rest of the unmatched string alone. So you still need to match the part of the string you want removed outside of the parentheses, so that only what matches in the parentheses remains in the string. If that made any sense...
[Using OSX here]
#!/usr/bin/perl -w
use strict;
my $s = 'one two three';
$s =~ s/([A-Za-z]+)/$1/;
print $s;
Ultimately I want to untaint and limitthe length of the string
$s =~ s/([A-Za-z]{1,8})/$1/; -- this does not seem to work as desired
I would suggest doing this in two steps to simplify matters. Untaint the string using the regex, and then if you want to limit the length of the string use the 'substr' function, this is more self documenting and simpler to devise, with little (if none, or even an improvement) loss of efficiency.
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
