Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

substring a path to return dir name

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

Avatar of leakim971
leakim971
Flag of Guadeloupe image

could you rephrase what you need?
maybe :
var URLname2 = "http://localhost:00000/BusinessRules/Rule/1";
URLname2 = URLname2.replace(/Rule\//gi,"")

Open in new window


User generated image
Avatar of lulu50

ASKER

Hi leakim971,

from this path;

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

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

var dir = "Rule";
Avatar of lulu50

ASKER

I need this result

URLname2 = "Rule";
Avatar of lulu50

ASKER

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
Avatar of lulu50

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of lulu50
lulu50
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

Thank you
I'm late! :(