Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: What can regular expressions NOT do?

by I0 (Priest)
on May 20, 2002 at 20:51 UTC ( #167962=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > What can regular expressions NOT do? - Answer contributed by I0

But Perl's m// operator is a more expressive grammar than formal regular expressions.
For example, \1 allows you to detect primes:
print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/
And s/// can be used to detect balanced parenthesis:
$_ = '(()(()()))'; (my $re=$_)=~s/((\()|(\))|.)/${[')','']}[!$3]\Q$1\E${['(','']}[!$2]/gs +; eval{/$re/}; print "Balanced" unless $@ =~ /unmatched/;

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2016-09-28 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (524 votes). Check out past polls.