Split string with a single occurence (not twice) of a delimiter in Javascript

前端 未结 6 1428
星月不相逢
星月不相逢 2020-12-18 05:04

This is better explained with an example. I want to achieve an split like this:

two-separate-tokens-this--is--just--one--token-another

->

6条回答
  •  甜味超标
    2020-12-18 05:27

    You would need a negative lookbehind assertion as well as your negative lookahead:

    (?

    http://regexr.com?31qrn

    Unfortunately the javascript regular expression parser does not support negative lookbehinds, I believe the only workaround is to inspect your results afterwards and remove any matches that would have failed the lookbehind assertion (or in this case, combine them back into a single match).

提交回复
热议问题