-5

I am working in angular2 I have a URL link,eg:-www.abcd.com/Computers_Accessories/panache-air-pc/P-coac-20620024815-cat-z.html#newId=P-coac-41130779424?trackId=paym&subTrackId=&infitag=1234

I need to cut the portion #newId=P-coac-41130779424 from the above URL and append it to the end of the URL , so that the new required Url looks like:- www.abcd.com/Computers_Accessories/panache-air-pc/P-coac-20620024815-cat-z.html?trackId=paym&subTrackId=&infitag=1234#newId=P-coac-41130779424 is there any method to apply Regex in typescript to get this result, or else any other proper method to achieve this

1 Answer 1

1

You can use the regex

(.*)(#newId=.*)(?=\?)(.*)

and replace it with (1st group)(3rd group)(2nd group)

check out the demo

let str = 'www.abcd.com/Computers_Accessories/panache-air-pc/P-coac-20620024815-cat-z.html#newId=P-coac-41130779424?trackId=paym&subTrackId=&infitag=1234';

str = str.replace(/(.*)(#newId=.*)(?=\?)(.*)/g, "$1$3$2");

console.log(str);

Sign up to request clarification or add additional context in comments.

1 Comment

what if i need to split it to something like that look link downstairs how is it done in typescript (stackoverflow.com/questions/49076594/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.