Tolgar
asked on
Regular Expression match in Javascript
Can you please let me know how I can express the following line using regular expressions in JavaScript?
http://www-internal.domain.com/support/devel/sandbox/anystring/anystring/anystring/anystring/anystring.html
The "anystring" can be anything, either a letter or a number and I don't know how many times it will repeat itself between slashes.
I want to match the part using regular expressions in JavaScript to the end of the directory where anystring.html HTML file locates.
Example:
http://www-internal.domain.com/support/devel/sandbox/tolgar/Myglnxa64_g934414_mytest/mybugs/mygecks/mychecks.html
Now I want to match: http://www-internal.domain.com/support/devel/sandbox/tolgar/Myglnxa64_g934414_mytest/mybugs/mygecks/
Again, I don't know how many sub directories there are until mychecks.html file.
Thanks,
Tolgar
http://www-internal.domain.com/support/devel/sandbox/anystring/anystring/anystring/anystring/anystring.html
The "anystring" can be anything, either a letter or a number and I don't know how many times it will repeat itself between slashes.
I want to match the part using regular expressions in JavaScript to the end of the directory where anystring.html HTML file locates.
Example:
http://www-internal.domain.com/support/devel/sandbox/tolgar/Myglnxa64_g934414_mytest/mybugs/mygecks/mychecks.html
Now I want to match: http://www-internal.domain.com/support/devel/sandbox/tolgar/Myglnxa64_g934414_mytest/mybugs/mygecks/
Again, I don't know how many sub directories there are until mychecks.html file.
Thanks,
Tolgar
Refer this post
http://www.codingforums.com/archive/index.php/t-9241.html
http://www.codingforums.com/archive/index.php/t-9241.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another option:
var input = "http://www-internal.domain.com/support/devel/sandbox/tolgar/Myglnxa64_g934414_mytest/mybugs/mygecks/mychecks.html";
alert(input.match(/sandbox\/(.+?)\.html/)[1]);
re kaufmed's solution, I don't think we're supposed to include the filename part of the file, which I believe your pattern does. You are excluding the filetype but not the filename.
Indeed. I read the example's output incorrectly. Good eye = )
(http://www-internal.domain.com/support/devel/sandbox/(?:\w*/)*)\w*.html