Regex for splitting a string using space when not surrounded by single or double quotes

后端 未结 15 2148
梦毁少年i
梦毁少年i 2020-11-22 03:15

I\'m new to regular expressions and would appreciate your help. I\'m trying to put together an expression that will split the example string using all spaces that are not s

15条回答
  •  忘了有多久
    2020-11-22 03:24

    If you want to allow escaped quotes inside the string, you can use something like this:

    (?:(['"])(.*?)(?\\\\)*\1|([^\s]+))
    

    Quoted strings will be group 2, single unquoted words will be group 3.

    You can try it on various strings here: http://www.fileformat.info/tool/regex.htm or http://gskinner.com/RegExr/

提交回复
热议问题