Reputation: 7230
I have this kind of text 1323-DI-004 (2013-07-16).pdf
and I want to have the date placed in parentheses. I tried with the regex (\(.*)\)
. It give this (2013-07-16)
. I want to have the same result but without parenthses.
This is for a VBA code.
Is it possible and how to do it?
Upvotes: 2
Views: 85
Reputation: 72905
Edit: you're using VBA, so
Dim myMatches As MatchCollection
Set myRegExp = New RegExp
myRegExp.Pattern = "\((.*)\)"
Set myMatches = myRegExp.Execute(subjectString)
MsgBox(myMatches(1).Value) 'I think this be your reference? You may need to iterate myMatches to get the right one
Assuming this is a fully PCRE compliant matching platform (PHP, PERL, etc. -- not javascript), use lookarounds to achieve this, matching the ()
on either side without including them in the capture:
(?<=\()(.*)(?=\))
See it in action: http://regex101.com/r/oI3gD6
If you're using javascript, this won't work, however you can use \((.*)\)
and retrieve the first capture group, which will be what's inside the ()
.
Upvotes: 1