Javascript Regexp - Match Characters after a certain phrase

You use capture groups (denoted by parenthesis).

When you execute the regex via match or exec function, the return an array consisting of the substrings captured by capture groups. You can then access what got captured via that array. E.g.:

var phrase = "yesthisismyphrase=thisiswhatIwantmatched"; 
var myRegexp = /phrase=(.*)/;
var match = myRegexp.exec(phrase);
alert(match[1]);

or

var arr = phrase.match(/phrase=(.*)/);
if (arr != null) { // Did it match?
    alert(arr[1]);
}

phrase.match(/phrase=(.*)/)[1]

returns

"thisiswhatIwantmatched"

The brackets specify a so-called capture group. Contents of capture groups get put into the resulting array, starting from 1 (0 is the whole match).


It is not so hard, Just assume your context is :

const context = https://medicoads.net/pa/GIx89GdmkABJEAAA+AAAA

And we wanna have the pattern after pa/, so use this code:

const pattern = context.match(/pa\/(.*)/)[1];

The first item include pa/, but for the grouping second item is without pa/, you can use each what you want.