Posted by: merly | December 23, 2008

extracting patterns in perl

In many applications we may need to extract certain numbers , characters or even a mixture of characters ans numbers from sentences….
the below code will help you

consider the below example

eg: id #23517348 – from reply

Our aim is to extract 23517348 from the above data

regex for extracting is:- /(\d+)/

=====================================
my $sub=$::FORM{desc’}; // suppose sub prints the data
id #23517348 – from reply

#print “$sub”;
$sub =~/(\d+)/;
print “$1″;

=======================
Output
=====
23517348


Leave a response

Your response:

Categories