madbee has asked for the wisdom of the Perl Monks concerning the following question:
Hello! I am trying to extract the protocol number which is alpha-numeric from a given string. My string is:
my $str="Study Protocol No. NBXF317N2201"; For this string, I'm trying to extract the term: using the following regular expression:
my ($prot) = $str =~ /Protocol (?:No\.? )?([A-Z0-9]{12})/;
This works fine. However, for some docs, I have the string "Number" instead of No. or No
For this: I tried to use matching within the expression like this:
my ($term) = $str =~ /Protocol (?:(No\.|Number)? )?([A-Z0-9]{12})/;
This just returns "Number" instead of: NBXF317N2201
So, given a string:"Study Protocol (No.|No|Number) NBXF317N2201", how can I modify my expression in order to extract NBXF317N2201 which is always a combination of alpha-and numbers and is always 12 characters long?
Thanks a lot in advance. Regards,madbee
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extract pattern from string
by kcott (Archbishop) on Jul 04, 2013 at 06:06 UTC | |
|
Re: Extract pattern from string
by hdb (Monsignor) on Jul 04, 2013 at 05:54 UTC | |
by madbee (Acolyte) on Jul 04, 2013 at 06:03 UTC | |
by hdb (Monsignor) on Jul 04, 2013 at 06:08 UTC | |
by madbee (Acolyte) on Jul 04, 2013 at 07:15 UTC | |
by AnomalousMonk (Archbishop) on Jul 04, 2013 at 19:23 UTC |