How to escape asterisk in regexp?

You have to escape it with a backslash:

/\*1\*/

Otherwise, an unescaped * in a RegExp will mean: Match 0 or more of the Preceding Character Group.

Update:

If you use the RegExp constructor, do it this way:

new RegExp("\\*1\\*")

You have to double-escape the backslashes because they need to be escaped in the string itself.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)