I had a look at other stackoverflow questions and couldn’t find one that asked the same question, so here it is:
How do you match the first and last characters of a string (can be multi-line or empty).
So for example:
String = "this is a simple sentence"
Note that the string includes the beginning and ending quotation marks.
How do I get match the first and last characters where the string begins and ends with a quotation mark (“).
I tried:
^"|$" and \A"\Z"
but these do not produce the desired result.
Thanks for your help in advance 🙂
Is this what you are looking for?
This will replace the first and last character of the input string with spaces if it starts and ends with
". It will also work across multiple lines since theDOTALLflag is specified by(?s).