Oops - explination wrong... Without the g it would return a scalar 1 if a match was found or false if not, you would need to backreference $1 to get the found value.
James -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Kuhns Sent: Tuesday, August 03, 2004 9:53 AM To: [email protected] Subject: RE: [brlug-general] noob regex question Regex alone: /\{([^\}]*)\}/g notice the g at the end - without it the regex would return a scalar with text1 in it Regex basically says: find a string that starts with { and ends with } but does not have any }'s in the middle (avoids greedy matches - if you use .* instead of [^\}]* you would get everything from the first { to the last }) Regex in action: #!/usr/bin/perl my $str = 'this is some {text1}. this is more {text2}. and yet some more {text3}.'; my @results = $str =~ /\{([^\}]*)\}/g; # displays text3 (last match found) print "$1\n"; # displays text1, text2 and text3 foreach $result (@results) { print $result."\n"; } James -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Hebert Sent: Tuesday, August 03, 2004 9:20 AM To: [email protected] Subject: [brlug-general] noob regex question Howdy, I have a bunch of text with multiple tokens in it demarcated by { and }. Sample text: this is some {text1}. this is more {text2}. and yet some more {text3}. blahdeblah. What would a regular expression to get these tokens out of the text look like, in a Perl script, say? Thanks, John __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail _______________________________________________ General mailing list [email protected] http://brlug.net/mailman/listinfo/general_brlug.net _______________________________________________ General mailing list [email protected] http://brlug.net/mailman/listinfo/general_brlug.net
