[removed] Invalid quantifier in regex

前端 未结 2 1720
孤独总比滥情好
孤独总比滥情好 2020-12-19 04:17

The regex is constructed on the fly, but I\'ve output it to firebug:

(.{1,38})(+|$\\n?)

the error is

invalid quantifier +|$         


        
2条回答
  •  庸人自扰
    2020-12-19 05:04

    The problem is the +, which is a quantifier you need to escape.

    Use this instead:

    /(.{1,38})(\+|$\n?)/
    

    or inside a string:

    "(.{1,38})(\\+|$\\n?)"
    

    If you want to match the literal $ followed by a newline, you need to escape the $ with \ (or \\ inside a string - see my last comment below this for an explanation).

    Here's some information on quantifiers.

提交回复
热议问题