in reply to Re^2: Extract pattern from string
in thread Extract pattern from string
I tried this:
my $str="Study Protocol Number NBXF317N2201"; my ($term) = $str =~ /Protocol (?:(?:No\.|Number)? )?([A-Z0-9]{12})/; print $term;
Another question: do you mean the . after No to be optional? Then it has to be
my $str="Study Protocol Number NBXF317N2201"; my ($term) = $str =~ /Protocol (?:(?:No\.?|Number) )?([A-Z0-9]{12})/; print $term;
UPDATE: Having thought about it, I would do the following which IMHO is simpler to read:
use strict; use warnings; for my $str ( "Study Protocol Number NBXF317N2201", "Study Protocol No. NBXF317N2201", "Study Protocol NBXF317N2201", "Study Protocol No NBXF317N2201" ) { my ($term) = $str =~ /Protocol (?:No\. |No |Number |)([A-Z0-9] +{12})/; print "$term\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Extract pattern from string
by madbee (Acolyte) on Jul 04, 2013 at 07:15 UTC |