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'
In reply to Re: Problem with regular expression
by AnomalousMonk
in thread Problem with regular expression
by MARVion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |