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: Regular Expressions: Re: [recruiter] PCRE backtracking: Edit Log



BillKSmith
Veteran

May 22, 2014, 5:19 AM


Views: 35070
Re: [recruiter] PCRE backtracking

I agree with FishMonger that it is probably not possible to do this with a regular expression. Note however that in native perl, very little additional code is required.


Code
use strict; 
use warnings;
while (my $case = <DATA>) {
if ($case =~ s/([a-zA-Z]+)([0-9]+)\s*/length "$1" gt length "$2"/re) {
print "Pass: $case\n";
}
else {
print "Fail: $case\n";
}
}
__DATA__
foobar12345
foob123
foo12
foo1234
fo123


OUTPUT:

Code
Pass: foobar12345 

Pass: foob123

Pass: foo12

Fail: foo1234

Fail: fo123


UPDATE:
A review of PCRE documentation ( http://www.pcre.org/pcre.txt) shows that capturing parenthesis are available. You should be able to write C code equivalent to my perl code.
Good Luck,
Bill

(This post was edited by BillKSmith on May 22, 2014, 7:47 AM)


Edit Log:
Post edited by BillKSmith (Veteran) on May 22, 2014, 7:47 AM


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

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