Reputation: 110462
I am trying to match an IMDb url, but I keep getting the following error:
/(^http://imdb\.com/title/tt(\d)+/\.+season=(\d)+(.+)?$)
|(^http://imdb\.com/title/tt(\d)+/(.+)?$)
/.test('http://www.imdb.com/title/tt0429046/?ref_=fn_al_tt_1')
Uncaught SyntaxError: Unexpected token ILLEGAL
What is this error and what should the correct input be?
Another option I could do is the broader:
/imdb.com\/title\/tt(\d)+/(.+)?$/.test('http://www.imdb.com/title/tt0429046/?ref_=fn_al_tt_1')
However, for this one I get Uncaught SyntaxError: Unexpected token .
Upvotes: 0
Views: 254
Reputation:
@smithy is correct answer.
Here they are escaped.
First one /(^http:\/\/imdb\.com\/title\/tt(\d)+\/\.+season=(\d)+(.+)?$)|(^http:\/\/imdb\.com\/title\/tt(\d)+\/(.+)?$)/
(
^ http://imdb\.com/title/tt
( \d )+
/
\.+ season =
( \d )+
( .+ )?
$
)
| (
^ http://imdb\.com/title/tt
( \d )+
/
( .+ )?
$
)
Second one /imdb\.com\/title\/tt(\d)+\/(.+)?$/
imdb \. com/title/tt
( \d )+
/
( .+ )?
$
Upvotes: 0
Reputation: 23002
Here is a working RegEx:
/(^http:\/\/www\.imdb\.com\/title\/tt(\d)+\/\.+season=(\d)+(.+)?$)|(^http:\/\/www\.imdb\.com\/title\/tt(\d)+\/(.+)?$)/
Upvotes: 0
Reputation: 27971
You need to escape the /
s within your regex, ie: http:\/\/
...etc.
Upvotes: 3