Solved

javascript regex to match specific directory construct

Posted on 2013-05-21
2
267 Views
Last Modified: 2013-05-22
Hello,
I am trying to write a regex expression that returns true or false based on the directory passed in. For example:

var pattern = new RegExp("/^\/application\/modules\/?\/models/i");

console.log(pattern.test("/application/modules/admin/models"));

I've been at this awhile and dont seem to be getting anywhere.. I have tried substituting in * for ? as well as various other constructs. Can someone explain to me what IM missing here?

500 points for working solution.
0
Comment
Question by:richardsimnett
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39186445
var pattern = new RegExp(/^\/application\/modules\/[^\/]*\/models/i);

Open in new window


http://jsfiddle.net/Mzest/
0
 

Author Comment

by:richardsimnett
ID: 39188054
How would I change this to make this work, as I was testing this I realized that there was something I overlooked.

var modulepattern = new RegExp(/^\/application\/modules\/[^\/]*\/models/i);

Example 1
modulepattern.test("/application/modules/test/models"); //returns true as it should - this is perfect

Example 2
modulepattern.test("/application/modules/test/models/test"); //should return false - but currently returns true (note the additional directory after the /models in the path
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

770 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