nnyby
nnyby

Reputation: 4668

javascript regex: matching a phone number

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.

Upvotes: 0

Views: 546

Answers (1)

John Kugelman
John Kugelman

Reputation: 361556

Lose the quotes:

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

Upvotes: 4

Related Questions