Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Problem with regular expression

by AnomalousMonk (Abbot)
on Feb 12, 2013 at 17:03 UTC ( #1018413=note: print w/ replies, xml ) Need Help??


in reply to Problem with regular expression

In most cases it works fine...

Further to choroba's post: MARVion: Your regex doesn't really work at all because almost everything in it is optional (i.e., has the  ? quantifier) except the  (\d+) bit at the end, so it is happy to match with and capture the first group of decimal digits in anything. What are you really after here?

>perl -wMstrict -le "my @in = ( 'TFS100', 'TFS 100', 'TFS-CR100', 'TFS-CR 100', 'TFS_100', 'TFS ID 100', 'TFS CR 100', 'TFS ID100', 'TFS-ID 100', 'TFS ID:100', 'TFS-ID: 100', '- TFS CR634: STRESS: H 17326,21600,', 'CR0080588', 'TFS0080588', qw(1234 xxx1234 123xxx xxx123xxx 123xxx456 xxx123xxx456), ); ;; for my $s (@in) { $s =~ m{ [Tt]? [Ff]? [Ss]? [-_\s]? [Cc]? [Rr]? [Ii]? [Dd]? :? \s? (\d+) }xms; print qq{'$1' <- '$s'}; } " '100' <- 'TFS100' '100' <- 'TFS 100' '100' <- 'TFS-CR100' '100' <- 'TFS-CR 100' '100' <- 'TFS_100' '100' <- 'TFS ID 100' '100' <- 'TFS CR 100' '100' <- 'TFS ID100' '100' <- 'TFS-ID 100' '100' <- 'TFS ID:100' '100' <- 'TFS-ID: 100' '634' <- '- TFS CR634: STRESS: H 17326,21600,' '0080588' <- 'CR0080588' '0080588' <- 'TFS0080588' '1234' <- '1234' '1234' <- 'xxx1234' '123' <- '123xxx' '123' <- 'xxx123xxx' '123' <- '123xxx456' '123' <- 'xxx123xxx456'


Comment on Re: Problem with regular expression
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018413]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2015-07-30 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls