Link to home
Start Free TrialLog in
Avatar of satmisha
satmishaFlag for India

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.
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Use something like this to detect it
\|".*".*".*"\|

Open in new window

https://regex101.com/r/zTHSnO/1
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

What exactly do you want the result returned to be?

  1. This is an example with a "C" double quoted grade in middle.
  2. "This is an example with a C double quoted grade in middle."
  3. This is an example with a C double quoted grade in middle.


»bp
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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"

Open in new window

Avatar of satmisha

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.
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.