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
TolgarAsked:
Who is Participating?
 
sjklein42Connect With a Mentor Commented:
sandbox\/(.*?)[^\/]+$

Open in new window

0
 
Terry WoodsIT GuruCommented:
0
 
jijeeshCommented:
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
käµfm³d 👽Commented:
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]);

Open in new window

0
 
sjklein42Commented:
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.
0
 
käµfm³d 👽Commented:
Indeed. I read the example's output incorrectly. Good eye  = )
0
All Courses

From novice to tech pro — start learning today.