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"; }
In reply to Re^3: Extract pattern from string
by hdb
in thread Extract pattern from string
by madbee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |