satmisha
asked on
find a double quote within string using regular expression
Hi Team,
I am having a text file having pipe separated string values. The issue is getting string within the string as shown below. I am looking for a regular expression or some solution to remove that quotes as shown in the desired text below.
Existing: "This string is ok."|"This is an example with a "C" double quoted grade in middle."|"Next line"
Desired: "This string is ok."|"This is an example with a C double quoted grade in middle."|"Next line"
Looking forward to hearing from you.
I am having a text file having pipe separated string values. The issue is getting string within the string as shown below. I am looking for a regular expression or some solution to remove that quotes as shown in the desired text below.
Existing: "This string is ok."|"This is an example with a "C" double quoted grade in middle."|"Next line"
Desired: "This string is ok."|"This is an example with a C double quoted grade in middle."|"Next line"
Looking forward to hearing from you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What exactly do you want the result returned to be?
»bp
- This is an example with a "C" double quoted grade in middle.
- "This is an example with a C double quoted grade in middle."
- This is an example with a C double quoted grade in middle.
»bp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can split on "|" and remove the quotation marks in the strings, then put it together. This will allow it to handle multiple quoted words in a string. Example:
string input = "\"This string has a \"quote\".\"|\"This is an \"example\" with multiple \"quoted\" words.\"|\"Next \"line\"\"";
string result = "\"" + String.Join("\"|\"", input.Split(new string[] { "\"|\"" }, StringSplitOptions.None).Select(s => s.Replace("\"", ""))) + "\"";
// result contains: "This string has a quote."|"This is an example with multiple quoted words."|"Next line"
ASKER
Guys appreciate your replies but the one that worked for me is: (?<!^)(?<!\|)"(?!\|)(?!$)
I could use this in UltraEdit pad editor to find the requested strings in the file.
I could use this in UltraEdit pad editor to find the requested strings in the file.
ASKER
Guys thanks a lot for your prompt reply though in my case I m using Perl script to search the string in large text file for the time being.
Open in new window
https://regex101.com/r/zTHSnO/1