javascript regex of a javascript string

后端 未结 4 1625
迷失自我
迷失自我 2020-12-04 04:14

I need to match a javascript string, with a regular expression, that is a string enclosed by single quote and can only contain a backslashed single quote.

The exampl

4条回答
  •  孤城傲影
    2020-12-04 04:29

    Try this

    /^'([a-z]*(?:\')?[a-z])+'$/

    See example here

    str = 'abc\'de\'fg';
    
    match = str.match(/^([a-z\\']+)$/g);
    

    Tested in Firebug console. Works with or without the escape chars.

提交回复
热议问题