Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Regular Expression match in Javascript

Posted on 2011-02-14
6
466 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:Tolgar
6 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34891621
0
 
LVL 5

Expert Comment

by:jijeesh
ID: 34891661
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 250 total points
ID: 34891670
sandbox\/(.*?)[^\/]+$

Open in new window

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34891782
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
 
LVL 16

Expert Comment

by:sjklein42
ID: 34891957
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34892089
Indeed. I read the example's output incorrectly. Good eye  = )
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question