parsings strings: extracting words and phrases [JavaScript]

前端 未结 10 669
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 19:20

I need to support exact phrases (enclosed in quotes) in an otherwise space-separated list of terms. Thus splitting the respective string by the space-character is not suffic

10条回答
  •  春和景丽
    2020-12-01 19:52

    how about,

    output = /(".+?"|\w+)/g.exec(input)
    

    then do a pass on output to lose the quotes.

    alternately,

    output = /"(.+?)"|(\w+)/g.exec(input)
    

    then do a pass n output to lose the empty captures.

提交回复
热议问题