Parse string with whitespace and quotation mark (with quotation mark retained)

前端 未结 3 1209
心在旅途
心在旅途 2020-12-11 04:42

If I have a string like this

create myclass \"56, \'for the better or worse\', 54.781\"

How can I parse it such that the resul

3条回答
  •  既然无缘
    2020-12-11 05:22

    Regex Demo

    (\w+|"[^"]*")
    

    Get the matches in the first capture group.

    1. \w+: Matches alphanumeric characters and underscore one or more times
    2. "[^"]*": Matches anything that is wrapped in double quotes
    3. |: OR condition in regex

提交回复
热议问题