简体   繁体   中英

Javascript Regular expression error in get string between two strings

I have string look like this :

"fdsgsgf.signature=xxxxx(bv)"

And i want to get xxxxx

With : var testRE = html.match(".signature=(.*)/\\(");

And when i run it i get exception that it's not valid regex.

Any idea why?

你需要双重转义反斜杠: ".signature=(.*)/\\\\(" 。这是一个有效的正则表达式,但它会匹配/ char。如果你不需要它,只需删除它;)

Some issues with your code:

  • You're missing starting slash / of your regex
  • Instead of .* you should better use [^(]+
  • dot needs to be escaped

Modified code:

html.match(/\.signature=([^(]+)/);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM