0

How can i use regex to get the keyword appName from possible url string like below

i have tried this /(?<=webapp/)(.*)(?=#)/g but it only works with example2 and example3

example1: http://localhost:1001/myapp/appName
example2: http://localhost:1001/myapp/appName#!/
example3: http://localhost:1001/myapp/appName#!/Test
example4: http://localhost:1001/myapp/appName/test/what
2

3 Answers 3

1

You can use this regex:

(?<=\/myapp\/)[^?#\/]+

RegEx Demo

  • [^?#\/]+: Match 1+ characters that are not in the character class i.e. ?,#,/
Sign up to request clarification or add additional context in comments.

Comments

0

You can use this:

    (\/myapp\/)(.*?)[^?#\/\n]+
    replace $2

Comments

0

I think you should change webapp to myapp. If the "appName" consists of only word characters [A-Za-z0-9_], you could use \w+:

(?<=myapp/)\w+

Comments

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.