Let’s assume that I have a string like this:
blah.blah.blah.(hi.there).[la.la].la.ext
what I want is a Bash regex that captures only the first part of the string:
blah.blah.blah
The following regex captures that, but it includes the dot:
[[ "blah.blah.blah.(hi.there).[la.la].la.ext" =~ ([^[(]*) ]]
so I have:
'blah.blah.blah.' in ${BASH_REMATCH[1]}
Tried multiple ways to get rid of the dot, but with no luck. Is there a regex that gives me that string without the final dot?
The regex should work with square brackets too, like:
'blah.blah.blah.[hi.there].(la.la).la.ext'
Thanks in advance.
Take everything (.*
) before a period (.
) followed by a round opening bracket ((
):
[[ "blah.blah.blah.(hi.there).[la.la].la.ext" =~ (.*).( ]] && echo "${BASH_REMATCH[1]}"
Output:
blah.blah.blah
2