Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## perl code question

Hi,

I have below code :

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

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

}
}```
What is the code doing ?? what function of the regular expression
Code:
```
\$abc =~ /^[^\d]{2,4}<([^>]+)>\d?\1\$/;```

2. Originally Posted by abcdef
Hi,

I have below code :

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

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

}
}```
What is the code doing ?? what function of the regular expression
Code:
```
\$abc =~ /^[^\d]{2,4}<([^>]+)>\d?\1\$/;```
- ^ is the begining of the string if is not between [ and ]
- [something here] means a list of alowed chars or ranges of chars
- the ^ inside means 'not match what follow'
- \d is one of 0 to 9 ( as a note [^\d] is same as \D
- {2,4} means 2 up to 4 times
- < means to much <, obvious
untill here \$abc must start with number with minim 2 digit and maxim 4, something like 00 to 9999
- (...) is a group, what is inside if match can be referenced later with \1 ... \9, based onf position, this is \1
- [^>]+ mean anuthing exept > but at least one character
- > means obious >
- \d? nothing or a digit that mean could be 0 to 9 or miss
- \1 is the reference to the group
- \$ end of \$abc

see perldoc for perlretut, perlrequick but i suggest to start with perlintro and learn perl

best regards

3. Originally Posted by oesxyl
- ^ is the begining of the string if is not between [ and ]
- [something here] means a list of alowed chars or ranges of chars
- the ^ inside means 'not match what follow'
- \d is one of 0 to 9 ( as a note [^\d] is same as \D
- {2,4} means 2 up to 4 times
- < means to much <, obvious
untill here \$abc must start with number with minim 2 digit and maxim 4, something like 00 to 9999
- (...) is a group, what is inside if match can be referenced later with \1 ... \9, based onf position, this is \1
- [^>]+ mean anuthing exept > but at least one character
- > means obious >
- \d? nothing or a digit that mean could be 0 to 9 or miss
- \1 is the reference to the group
- \$ end of \$abc

see perldoc for perlretut, perlrequick but i suggest to start with perlintro and learn perl

best regards
So, could you advice in more detailed ??
What will output for my(\$abc) = "fred<hello>3hello";
What the regualr expression try to do/search for my(\$abc)???

4. Originally Posted by abcdef
So, could you advice in more detailed ??
perldoc perlretut

What will output for my(\$abc) = "fred<hello>3hello";

What the regualr expression try to do/search for my(\$abc)???
nothing

best regards

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•