Reputation: 11
I want to get "FileType"
using a Regular Expression.
Here is a example string:
randomname-id-mininthostname-FileType_20221118.zip
I tried (?=-).*(?<=_)
but it will return "-minint-FileType_"
Upvotes: 1
Views: 41
Reputation: 112682
Replace .*
which stands for any number of any character by [^-]*
which stands for any number of any character except -
. Or even better, since we want to capture at least one characxter: [^-]+
.
You inverted lookahead and lookbehind. I corrected that as well.
(?<=-)[^-]+(?=_)
Upvotes: 2