...
You could download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr and use this Regular Expression formula to
extract the
alphanumeric text string within the last set of "(...)"
...
=REGEX.SUBSTITUTE(A1,".*\((\w+)\).*$","[1]")
Or use assertions.
=REGEX.MID(A1,"(?<=\()[^()]*(?=\))")
If you are going to use assertions that way, per the OP's requirements,
you
need to ensure you return the last match.
Given, for example:
My Text String (XPYZ) (MTS)) in addition
your REGEX.MID returns (XPYZ),
So, I would use:
=REGEX.MID(A1,"(?<=\()[^()]*(?=\))",-1) or
=REGEX.MID(A1,"(?<=\()[^()]+(?=\)[^(]*$)")
But I've been purposely trying to avoid using lookbehind assertions since
they
are not supported in VBScript. And often enough, it has happened that
I've had
to switch to VBA.
Also begs the question whether to be as inclusive as possible within
the parentheses. If so, [^()]* matches more substrings than \w+.
Absolutely correct, and a good point to make explicitly. (That is why,
in my
description, I wrote "alphanumeric text string".)
Now, having written all that, and thought about it some more, it appears
as if
the look-behind assertion may not even be necessary!
For example:
[^()]+(?=\)[^(]*$)
or even:
\w+(?=\)[^(]*$)
or
[A-Z]+(?=\)[^(]*$)
All seem to work, and would work in either PCRE or VBScript.
Thanks.
--ron