|laziness, impatience, and hubris|
Re: Parsing/regex help requiredby roboticus (Chancellor)
|on Sep 27, 2021 at 13:32 UTC ( #11137038=note: print w/replies, xml )||Need Help??|
You generally need to figure out how to describe the problem to yourself to guide yourself to a solution. You didn't present any requirements, but let's assume from your example that you want to recognize lines that are numbered (i.e., begin with a number followed by a period) and include a hyphen surrounded by whitespace.
There are several ways you can accomplish it. You've already mentioned index and substr, another way could be to use split, or as you mention in the title a regular expression.
For a regular expression, you just build the expression bit by bit, like this:
The parenthesis tell perl to capture the part of the string you care about, so later if you find a match, you can use the matched parts. The first capture group will be in variable $1, the next in $2 and so on. A normal perl installation will have a good bit of documentation on regular expressions, so be sure to look over:
Don't forget that you can check the perl documentation index via perldoc perldoc to see which documents may be helpful at a given time.
When your only tool is a hammer, all problems look like your thumb.
In Section Seekers of Perl Wisdom