I gather that your search phrase will be determined at run time, and not only the phrase, but also whether the data comes before or after the phrase.
How is your program going to be notified of the search phrase? Is there some way it can also be notified of the positioning of the numerical data?
If you have any control over the earlier stage where the search phrase is identified, ask to have the search phrase specified as a regular expression complete with capturing parentheses.
sub capture_numbers { my ( $search_phrase ) = @_; croak "Search phrase $search_phrase lacks capturing parentheses" if $search_phrase !~ /\(/; my @results; while <LOG_FILE> { my ( $desired_number ) = /$search_phrase/o; push @results, $desired_number; } }
This sub accepts either of your two example search phrases with their differing syntax:
In reply to Re: search pattern with digits
by Narveson
in thread search pattern with digits
by mercuryshipz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |