开发者

javascript regex: matching a phone number

开发者 https://www.devze.com 2023-01-10 16:13 出处:网络
how do I match this phone number in Javascript? > str \"(555) 555-3300\" > str.match( \'/\\(555\\) 555-3300/gi/\' )

how do I match this phone number in Javascript?

> str
"(555) 555-3300"
> str.match( '/\(555\) 555-3300/gi/' )
null
> str.match( '/(555) 555-3300/gi/' )
null

I bet someone can 开发者_运维问答answer this in 2 seconds. Googling the problem didn't help me.

Update

Also tried without the quotes:

str.match(/\(555\) 555-3300/gi/)
SyntaxError: Unexpected token )

Ultimately I'm trying to replace the phone number with a different one.


Lose the quotes:

str.match(/\(480\) 945-3300/g)
0

精彩评论

暂无评论...
验证码 换一张
取 消