[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

javascript regex to match specific direcotry

Hello,
I have the following regex (provided to me from another question I asked). 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

I need to know what to add to the regex pattern to make both examples produce the desired results.

Worth 500 points.
0
richardsimnett
Asked:
richardsimnett
1 Solution
 
Terry WoodsIT GuruCommented:
Try this:
var modulepattern = new RegExp(/^\/application\/modules\/[^\/]*\/models\/?$/i); 

Open in new window


Tested here: http://jsfiddle.net/wmM4H/

Note that I've allowed there to be an optional / on the end. If you don't want to allow that, then use:

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

Open in new window

0
 
richardsimnettAuthor Commented:
Perfect. Thanks so much!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now