Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regular Expression match in Javascript

Posted on 2011-02-14
6
Medium Priority
?
476 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
[X]
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
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 1000 total points
ID: 34891670
sandbox\/(.*?)[^\/]+$

Open in new window

0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

688 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