in reply to Regular Expression on special character and alphanumeric values

my $string = "{'totalResultsCount':71-24,'securityList':[{'cusip':'91% +279-6.H:Y8','issueDate':'2016-06-02T00:00:00','securityType':'Bill'}" +; $string =~ /'cusip':'([\w\-\$\.\%\:]+)'/; if ( defined $1 ) { $string = $1; print "first is : $string \n" for $string =~ s/\W//g;; } else { print " first is not defined\n"; }
C:\Users\james\Desktop\perlmonks>pm.pl first is : 912796HY8

EDIT:

shorter code:

my $string = "{'totalResultsCount':71-24,'securityList':[{'cusip':'91% +279-6.H:Y8','issueDate':'2016-06-02T00:00:00','securityType':'Bill'}" +; $string =~ s/.*('cusip':'([\w\-\$\.\%\:]+)').*/$2/g; print "first is : $string \n" for $string =~ s/\W+//g;
C:\Users\james\Desktop\perlmonks>pm.pl first is : 912796HY8

EDIT: changed print "first is : $string \n" if $string =~ s/\W+//g; to print "first is : $string \n" for $string =~ s/\W+//g;

Replies are listed 'Best First'.
Re^2: Regular Expression on special character and alphanumeric values
by perlmad (Sexton) on May 31, 2016 at 04:26 UTC

    thanks to all it's working awesome once again thanks for your precious time to spend to my question