Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Replace substring1 with substring2 only when substring1 has non-whitespace border characters

  •  09-24-2010, 4:22 PM

    Replace substring1 with substring2 only when substring1 has non-whitespace border characters

    I am performing a grep find and replace in my text editor TextWrangler on a very large CSV data file.

    I have a source string of

    hello??world ??goodnight?? moon?? wake up

    and would like to replace the ?? substring with -- ONLY when it is bounded by non-whitespace characters on both sides, yielding a target string of

    hello--world ??goodnight?? moon?? wake up

     I have tried the following regex:

    ([\S]{1})?[\?]{2}([\S]{1})?

    with the replace operation

    \1\-\-\2

    but the ?? within ??goodnight?? and  moon??  are still being matched even though they are both bordered by whitespace on one side.

View Complete Thread