1
I have a string
url
and I need to withdraw the word Dashboard and all subsequent characters (including bars).
Example:
"Algumcoisa/Dashboard/Outracoisa/Maisalgumacoisa"
I want you to stay like this:
"Algumacoisa/"
I’ve tried to:
pathname = window.location.pathname
url = pathname.replace("/Dashabord.*/",'')
I can always test that code on regex
like the https://www.regextester.com/99144
, but I can never accomplish replace
.
Could you explain what the code does?
– Codigo de Senior
Calm down @Codigodesenior I already know how the site works and I just explained !
– novic
@novic you can explain why my approach is not executed by javascript?
– hellysonMacedo
@hellysonMacedo work with
regex
I do not like, I do not recommend, only in the last case, because, if there are ready methods that can solve your problem, use it is quieter in its development and is even clearer for later changes. Because yours did not work I have to do a test but, must be wrong the test so did not get the expected result.– novic
Well I discovered and I will also make available as a solution! @hellysonMacedo
– novic
@novic thank you so much for your new solution and even more for the correction you made in mine, I broke my head a lot thinking that the mistake was in regex and it never crossed my mind that it was the quotation marks.
– hellysonMacedo
Regex is so @hellysonMacedo I particularly hate to solve, but in some moments it is inevitable ..
– novic