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:
Regex for consequtive integers

 



asif
New User

Jan 21, 2011, 3:20 PM

Post #1 of 2 (2955 views)
Regex for consequtive integers Can't Post

Hello,

Could you please help me with regular expressions for idenifying strings that have numerals in them which are consequtive integers. For eg. I need to identify the following strings with the regex pattern.

A12345

12

FB123

Your time is highly appreciated. Thanks,

Asif


BillKSmith
Veteran

Jan 21, 2011, 7:07 PM

Post #2 of 2 (2947 views)
Re: [asif] Regex for consequtive integers [In reply to] Can't Post

Do it in two steps. First extract the longest string of digits. Then test if that pattern is found in the string of consecutive digits.


Code
use strict; 
use warnings;
use Readonly;
Readonly::Scalar my $CONSECUTIVE => '0123456789';
while (<>){
my( $numeric_string ) = /(\d+)/xms;
if ($numeric_string and $CONSECUTIVE =~ /$numeric_string/) {
print;
}
}

Good Luck,
Bill

 
 


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

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