Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing the text after an equal sign with regexp?

I would like to know if there is a code, preferable Regexp, that can get all the text after an equal sign.

For example:

3+4=7

Results:

7

Is this even possible? I hope so, thanks in advance.

like image 824
Shawn31313 Avatar asked Feb 23 '23 02:02

Shawn31313


1 Answers

var s = "3+4=7"; 
var regex = /=(.+)/; // match '=' and capture everything that follows
var matches = s.match(regex);
if (matches) {
    var match = matches[1];  // captured group, in this case, '7'
    document.write(match);
}

Working example in jsfiddle.

like image 174
João Silva Avatar answered Feb 24 '23 18:02

João Silva