Regex eError when using {1}+ possessive quantifier in JavaScript regex

后端 未结 1 985
旧时难觅i
旧时难觅i 2020-12-21 18:45

Since I am learning Javascript and Express.js at the same time I was experimenting around with regular expressions when making a get request

To familiaries my self w

相关标签:
1条回答
  • 2020-12-21 19:03

    JavaScript does not support possessive quantifiers. The error you are seeing occurs because the + can only be used as a greedy one-or-more quantifier.

    The chart you reference is from Oracle, and is explaining the quantifiers supported by Java, not JavaScript.

    You don't need to resort to anything special to do the kind of matching you want.

    If you want to match "a string ending in a /, with no other slashes in it, you can use:

    /[^/]+\/$/
    

    One or more non-slashes, followed by a slash, followed by the end of the string.

    0 讨论(0)
提交回复
热议问题