I used this solution if(/([a-z0-9\t ]*)>([a-z0-9\t ]*)/gi) { $string1 = $1; $string2 = $2; }
Quoting Robert Citek <[EMAIL PROTECTED]>: > > On Saturday, Oct 30, 2004, at 20:52 US/Central, John W. Krahn wrote: > > [EMAIL PROTECTED] wrote: > >> I have to match patterns of the format > >> string1>string2 > >> where the strings 1 & 2 can contain alphabets,numbers and spaces. > The > >> string are separated by '>' sign. I wrote the following code for > this. > >> if(/([a-z]*[A-Z]*[0-9]*[\s]*)>([a-z]*[A-Z]*[\s]*[0-9]*)/g) { > >> $string1 = $1; > >> $string2 = $2; > >> } > >> This picks up only the first character in string 2 whereas I want > >> everything till the end of the $_ to be in the string. $_ is > >> terminated > >> by \n. > >> I cannot understand what I am missing in the regular expression. > > > > > > my ( $string1, $string2 ) = > > /^([[:alnum:][:blank:]]*)>([[:alnum:][:blank:]]*)$/ > > How married are you to using a regular expression? An alternative > may > be to use split: > > my ($string1, $string2) = split(">", $_, 2) ; > > For example: > > $ perl -e ' > $_ = "[EMAIL PROTECTED]>def456&*(" ; > my ($string1, $string2) = split(">", $_, 2) ; > print "$string1, $string2\n" ; > ' > > If you still want to use the RegEx, you may be able to lighten up the > > restrictions on the characters in the RegEx: > > $ perl -e ' > $_ = "[EMAIL PROTECTED]>def456&*(" ; > m/(.*)>(.*)/ ; > print "$1, $2\n" ; > ' > > Is that close to what you were trying to do? In any case, let the > list > know what the final solution looks like. > > Regards, > - Robert > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>