I am trying to use double quotes with in the regex expression. However, as we all know that double quotes will be considered as a string. I was wondering if we can get over this and find a solution over here.
Ex: system.Text.RegularExpressions.Regex.Match(“This is a sample ‘sap’”,“'.*'”)---- This works fine.
system.Text.RegularExpressions.Regex.Match(“This is a sample “sap””,“'.*'”)---- This does not work fine.
If we replace single quotes for sap with double quotes, it will throw up an error. Do we have a solution for this case?
first off, you need to embed the inner quotes in your string. You can do this by using 2 quotes, like this:
Then for pattern, you can change the quotes in brackets to look for both single and double quotes.
You can also use a look behind and ahead to pull in only the text between the quotes using ?<= and ?=