Reputation: 329
The regex
(file\..*$)
matches "file.xml" correctly in
$cd = "..\folder\file.xml"
but I'd like to ignore the trailing quote via regex if possible
Upvotes: 2
Views: 2229
Reputation: 9650
Move the last char along with the end marker out of the group:
(file\..*).$
https://regex101.com/r/bZ7vV5/1
Or if you may have a non-quote last char which you would like to capture instead, then specify this quote explicitly but as optional ("?
) and make the previous match non-greedy (.*?
):
(file\..*?)"?$
https://regex101.com/r/bZ7vV5/3
Upvotes: 0
Reputation: 671
You can update your regular expression to the following:
(file\..*?)"?$
That'll make sure that if there is a trailing quote it will not be captured.
Upvotes: 1
Reputation: 43189
You could say: anything not a "
:
(file\.[^"]*)"$
(file\.[^"]*)
Upvotes: 1