Skip to content

Instantly share code, notes, and snippets.

@worp1900
Last active October 11, 2017 07:11
Show Gist options
  • Save worp1900/4d40219119294b5a111396834dc77a0c to your computer and use it in GitHub Desktop.
Save worp1900/4d40219119294b5a111396834dc77a0c to your computer and use it in GitHub Desktop.
Helpful regular expressions (pcre) I often use
(?<![\S"])([^"\s]+)(?![\S"])
Find all strings not enclosed in quotes. Workx ok well. Often used to add quotes to JSON notation that doesn't have it yet. Currently doesn't detect brackets like [, [, }. That needs some fixing.
Source: https://stackoverflow.com/questions/11324749/a-regex-to-detect-string-not-enclosed-in-double-quotes
@worp1900
Copy link
Author

Not yet well working. Wanting to use it to wrap JSON structures in correct quotes.

Example:

{
    ID: "1325",
    number: "269",
    array: [{
        ID: "1325-20131155303"
    }]
}

Should be this:

{
    "ID": "1325",
    "number": "269",
    "array": [{
        "ID": "1325-20131155303"
    }]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment