#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Posts
    23
    Rep Power
    0

    Replacing all spaces outside of quotes


    Language regex is used: Visual Basic .net

    What I want accomplished:
    To replace all spaces within the document to a certain character (Let's just say # for now), but only if the space is not contained within quotes.

    Example Document:
    Code:
    This is a single line
    This is a "second line"
    This is "Line #3"
    After Regex it should like:
    Code:
    This#is#a#single#line
    This#is#a#"second line"
    This#is#"Line #3"
    It's fairly simple to just replace all spaces with a # symbol, but I'm stumped for how to go about making sure not to change spaces contained within quotes.

    Any help would be greatly appreciated!
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,128
    Rep Power
    9398
    The easiest way I know is to first split the text into quoted and not-quoted chunks, and then run the space-># conversion on the not-quoted parts.

    Also opens the possibility of doing other stuff to the not-quoted parts in the future.

IMN logo majestic logo threadwatch logo seochat tools logo