Good post. They say that, if you have a problem, and you solve with a regular expression, now you have two problems. That said, for all their challenge, they are powerful, and this is one situation where I might choose to use a (very well documented) regex. FWIW, I just posted a Note with some code using a regex to solve this.
The regex: ^ (\d+|\*) f (.*) (\d+|\*) l (.*) $
Spaces added for clarity. It says: starting at the beginning of the string there are either some digits OR the literal '*' followed by a literal 'f' followed by some characters followed by some digits OR the literal '*' followed by a literal 'l' followed by some characters to the end of the string. Clear as mud, right? :)
Indeed–and that's why I wanted to add a note in the article to point those brave enough to regex. You're absolutely right, despite their challenges, for situations such as this one, they're ideal!
Good post. They say that, if you have a problem, and you solve with a regular expression, now you have two problems. That said, for all their challenge, they are powerful, and this is one situation where I might choose to use a (very well documented) regex. FWIW, I just posted a Note with some code using a regex to solve this.
The regex: ^ (\d+|\*) f (.*) (\d+|\*) l (.*) $
Spaces added for clarity. It says: starting at the beginning of the string there are either some digits OR the literal '*' followed by a literal 'f' followed by some characters followed by some digits OR the literal '*' followed by a literal 'l' followed by some characters to the end of the string. Clear as mud, right? :)
The Note with a working example:
https://substack.com/profile/195807185-wyrd-smythe/note/c-102034331
Indeed–and that's why I wanted to add a note in the article to point those brave enough to regex. You're absolutely right, despite their challenges, for situations such as this one, they're ideal!