CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
what below code do

 



abcdef
New User

Feb 9, 2011, 10:31 PM

Post #1 of 2 (1797 views)
what below code do Can't Post

Hi,

I have below code :



my($abc) = "fred<hello>3hello";
$abc =~ /^[^\d]{2,4}<([^>]+)>\d?\1$/;

if (defined($1)) {
print "$1\n";
} else {
print "not found\n";

}
}

What is the code doing ?? what function of the regular expression

$abc =~ /^[^\d]{2,4}<([^>]+)>\d?\1$/;

??


budman
User

Feb 10, 2011, 3:26 PM

Post #2 of 2 (1784 views)
Re: [abcdef] what below code do [In reply to] Can't Post


In Reply To
What is the code doing ?? what function of the regular expression

$abc =~ /^[^\d]{2,4}<([^>]+)>\d?\1$/;

??



Code
  /^                       start of line 
[^\d]{2,4} match any non-digit (chars)
containing between 2 and 4 letters
<([^>]+)> inside the angle brackets store the
contents in $1 upto the first
right angle bracket
\d?\1 then check for one digit and
look-ahead (?) for the text we stored
in $1 (\1 is a reference to $1)
$/ with nothing else til the end of the line


Works for
"fr<hello>3hello"
"fre<hello>3hello"
"fred<hello>3hello"

Then prints 'hello' in the case.

"xx<testing>9testing"
"xxx<testing>9testing"
"xxxx<testing>9testing"

These will also work, and print 'testing'

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives