locked
Need regular expression to match a standalone double quote and comma RRS feed

  • Question

  • Hi,

    I have a string like this (strings wrapped by double quotes and each string seperated by comma)

    "surya","27","100, gree"ns road, london",

    If you see the the , and the " appear inside a string like gre"ns and road, london etc.

    I need to remove such double quotes and commas that appear inside a string (that is wrapped within double quotes.

    I DONT want to remove patterns like ","  

    Any ideas ? PLEASE HELP

    THANKS IN ADVANCE

    Surya
    Thursday, February 7, 2013 9:28 PM

Answers

  • Hi Surya,

    Nice to see you.

    Based on my understanding, this goal can be achieved by two deletion:

    1. delete the commas which is not behind of double quotes(")

    The find RE is:

    ([^"]),

    the replacement RE is:

    $1

    2. delete the double quotes which is not behind and after a commas

    The find RE is:

    ([^,])"([^,])

    the replacement RE is:

    $1$2

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Durgesh Chaudhary Friday, February 8, 2013 8:59 AM
    • Marked as answer by Mike Feng Thursday, February 14, 2013 10:38 AM
    Friday, February 8, 2013 7:41 AM

All replies

  • Hi Surya,

    Nice to see you.

    Based on my understanding, this goal can be achieved by two deletion:

    1. delete the commas which is not behind of double quotes(")

    The find RE is:

    ([^"]),

    the replacement RE is:

    $1

    2. delete the double quotes which is not behind and after a commas

    The find RE is:

    ([^,])"([^,])

    the replacement RE is:

    $1$2

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Durgesh Chaudhary Friday, February 8, 2013 8:59 AM
    • Marked as answer by Mike Feng Thursday, February 14, 2013 10:38 AM
    Friday, February 8, 2013 7:41 AM
  • Nate that your text looks like comma-separated values (CSV). In this case the embedded quotes should be represented by two quotes [http://en.wikipedia.org/wiki/Comma-separated_values].

    Friday, February 8, 2013 8:54 AM
  • Thanks for your answer Mike Feng !!! nice to see you too !!.
    Thursday, February 14, 2013 2:27 PM
  • Hi,

    I tried the regular expressions, however it also selects the preceding/succeeding characters. I only need to select the standalone " and the , so that I can replace it with empty string using Regex.Replace("<regular expression> , "");

    what I am trying to achieve is removal of those " and , alone.

    PLEASE HELP

    Thanks in advance

    Surya


    Wednesday, February 20, 2013 10:44 AM