Javascript 是否在与regexp等号后显示文本?

Javascript 是否在与regexp等号后显示文本?,javascript,regex,Javascript,Regex,我想知道是否有一个代码,最好是Regexp,可以得到等号后的所有文本 例如: 3+4=7 结果: 七, 这可能吗?希望如此,提前谢谢 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

我想知道是否有一个代码,最好是Regexp,可以得到等号后的所有文本

例如:

3+4=7

结果:

七,

这可能吗?希望如此,提前谢谢

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);
}
.

/=(.*)/
中的工作示例应该足够了,因为它将在第一个=

其他可能性(也可以转录成Perl以外的语言)

$x=“foo=bar”;

如果$x=~/(?我怎么使用regexp?我可以得到一个JSFIDLE示例吗?简单来说,我已经用javascript编写了一个+1示例。我建议向OP解释文本将在组1中捕获。为什么使用regex更好?只需在
上拆分“=”
。在任何情况下,你都需要说出你使用的是什么语言;这是有区别的。如果你能说出为什么它不起作用,那会更有用,因为很明显,你的措辞方式,它会很好地起作用,而且会更容易。
$x = "foo=bar";
print "$'" if $x =~ /(?<==)/;   # $' = that after the matched string
print "$&" if $x =~ /(?<==).*/; # $& = that which matched
print "$1" if $x =~ /=(.*)/;    # first suggestion from above