js regular matches the characters between two strings, and first-level matches strings with backslashes

Regularly matches characters between two strings

Use regular expressions to match, here is matching the string between 'allowed=v' and 'l'

let str = "lorem ballaalal,allowed=valuelalala"
str = str.match(/allowed=v(\S*)l/); 
console.log('====>',str)

The output is:
Insert image description here

Characters with backslash

Strings with backslashes need to be escaped first. In strings, backslashes are used as escape characters. If you want to output '', you actually need to enter ''. The first one means escape, and the second one means escape. One is the actual output.
Use regular expressions to match, here is matching the string between 'allowed=v' and '' (backslash)

let str = "lorem ballaalal,allowed=value\\lalala"
str = str.match(/allowed=v(\S*)\\/); 
console.log('====>',str)

Guess you like

Origin blog.csdn.net/qq_37617413/article/details/121384734