JavaScript match substring after RegExp

javascript, regex, string, substring

Solution

You can use a regexp like the one Bart gave you, but I suggest using match rather than replace, since in case a match is not found, the result is the entire string when using replace, while null when using match, which seems more logical. (as a general though).

Something like this would do the trick:

function getNumber(string) {
    var matches = string.match(/-mr([0-9]+)/);
    return matches[1];
}
console.log(getNumber("something30-mr200"));

Problem

I have a string that look something like ``` something30-mr200 ``` I would like to get everything after the `mr` (basically the # followed by mr) *always there is going to be the `-mr` Any help will be appreciate it.

Original source