regular expression help finding href within window.open()

J

jd

hi all,

i'm using regular expression to find the url of the page to be opened
using the window.open().

typical urls look like this http://domain.com/path-to-page.html

right now i'm trying href.match(/http:\/\/domain\.com\/\w?\.html/)

and this will get me http://domain.com/path but not everything to
html.

does anyone have some tips they can offer?

i've tried
href.match(/http:\/\/domain\.com\/\w*\.html/)
href.match(/http:\/\/domain\.com\/*\.html/)

and they don't work.

thanks for any help you can offer
 
C

Cah Sableng

hi all,

i'm using regular expression to find the url of the page to be opened
using the window.open().

typical urls look like thishttp://domain.com/path-to-page.html

right now i'm trying href.match(/http:\/\/domain\.com\/\w?\.html/)

'-' character is not word characters, so it \w won't make it.
Use '-' with \w enclosed by square bracket, and prepend '-' with '\'
because it is regex's special character.

try:
/^http:\/\/domain\.com\/[\w\-]+\.html/
 
R

RobG

i'm using regular expression to find the url of the page to be opened
using the window.open().
typical urls look like thishttp://domain.com/path-to-page.html
right now i'm trying href.match(/http:\/\/domain\.com\/\w?\.html/)

'-' character is not word characters, so it \w won't make it.
Use '-' with \w enclosed by square bracket, and prepend '-' with '\'
because it is regex's special character.

try:
/^http:\/\/domain\.com\/[\w\-]+\.html/

Presumably the domain name is in a string of other stuff and will be
enclosed in quotes, so maybe:

/http:[^\'\"]+\.html/

will suit better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Regular expression help 9
Regular expression problem 13
Help please 8
Regular Expression Help? 5
Regular Expression Help 3
Regular Expression Help please! 7
regular expression help... 5
Regular expression help 3

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top