0
http://localhost:3000/?code=85b1a3645tgreg1f54221d8d9f54923b88ade29945yttrtgdg903

I am trying to get whatever comes after 'code=' from this string. How could I do this?

  • Why not parse the url with javascript instead of using a regex, and then for example use split? – The fourth bird Jul 16 '20 at 20:06
  • Does this answer your question? [How can I use regex to get all the characters after a specific character, e.g. comma (",")](https://stackoverflow.com/questions/4058923/how-can-i-use-regex-to-get-all-the-characters-after-a-specific-character-e-g-c) – Vahe Yavrumian Jul 16 '20 at 20:07

2 Answers2

0

You could use

code=(.+)

See a demo on regex101.com.


In JavaScript this could be:

let string = 'http://localhost:3000/?code=85b1a3645tgreg1f54221d8d9f54923b88ade29945yttrtgdg903';
let m = string.match(/code=(.+)/);
console.log(m[1]);

But it would possibly be more straight-forward to parse the url as it is and use the query part accordingly.

Jan
  • 42,290
  • 8
  • 54
  • 79
0

str.match(/code=(.*)/)[1] will do that for you.

Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185