substring a path to return dir name

lulu50
lulu50 used Ask the Experts™
on
Hi,

I need your help!!

My javascript:
 var URLname2 = document.location.href.match(/.*\/(.*)$/)[0];

the variable "URLname2" generate this path below
"http://localhost:00000/BusinessRules/Rule/1"

what I want for the "var URLname2" is to pull just the word "Rule" from the whole path

I'm not sure how this is done, but I tried Substring and didn't work. 

Thank you so much for your help, 
Lulu50

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
could you rephrase what you need?
leakim971Multitechnician
Top Expert 2014

Commented:
maybe :
var URLname2 = "http://localhost:00000/BusinessRules/Rule/1";
URLname2 = URLname2.replace(/Rule\//gi,"")

Open in new window


Capture.JPG

Author

Commented:
Hi leakim971,

from this path;

"http://localhost:00000/BusinessRules/Rule/1"

I want to store the word "Rule" in a variable

var dir = "Rule";
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I need this result

URLname2 = "Rule";

Author

Commented:
I want to remove "http://localhost:00000/BusinessRules/
and
I want to remove "/1"
from this path: "http://localhost:00000/BusinessRules/Rule/1"
and
store "Rule" in my variable URLname2

Author

Commented:
I got it

Thank you

            var pathArray = window.location.pathname.split('/');
            var secondLevelLocation = pathArray[2];
var URLname2 = document.location.href.match(/.*\/(.*)$/)[0];
var rule = URLname2.split('/')[4];

Open in new window

Commented:
var pathArray = window.location.pathname.split('/');
            var secondLevelLocation = pathArray[2];

Author

Commented:
Thank you
I'm late! :(

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial