I am trying to extract a portion of text that is embedded within parenthesis in a text string:
"Dominion Diamond Corporation (DDC) "
(I want to extract DDC).
Perusing the interwebs suggests that the regular expression
"\([^)]*\)"
will be useful.
I try the following:
ret = Regex(regExp)
match(ret, "Dominion Diamond Corporation (DDC) ")
Output:
RegexMatch("Dominion Diamond Corporation (DDC", 1="Dominion Diamond Corporation (DDC")
However, when i enter the regex expression into the match function directly:
match(r"\([^)]*\)"t, "Dominion Diamond Corporation (DDC) ")
The output is:
RegexMatch("(DDC)")
Why / how are these two expressions different? How do I interpolate an arbitrary regex expression into the first arg for match?
r"string"
usually means raw string (i.e. Python). I suspect it was stripping the backslashes before. I have no clue why there's at
at the end, though. – Laurel