Avoid regex to capture contents of string (between quotes) -
i'm using following regex capture array of string follows conditions (e.g.: it's not prepended letter or number, , contains strings surrounded single or double quotes):
/^?[ =>]\[(('|")[^('|")\s]*('|")(, ?)?)+\]/
it should capture
["bla", "ble", "blo"]
however, should not capture that, if it's part of string between (single or double) quotes:
'["bla", "ble", "blo"]'
what should add avoid capturing unwanted case?
add negative lookbehind/lookahead expression pattern:
(?<!['])(?!['])(\[(('|")[^('|")\s]*('|")(, ?)?)+\])
worked me when testing, may depend on regex engine.
Comments
Post a Comment