开发者

What's wrong with this Perl regular expression?

I have 开发者_如何学编程a lines like this

NF419andZNF773 (e=10^-92,). 
ZNF571 (e=2 10^-14,)

What's the regex for extracting the results above so that it gives

NF419andZNF773 - 10^-92
ZNF571 - 2 10^-14

I tried this but fail.

$line =~ /(\w+)\s\(e=\s(.*),\)/;
print "$1 - $2\n";


You're close, the ending of your regex is failing since it expects space before the exponent. try this:

$line =~ / (\w+) \s+ \( e= ([^,]+) /x;


Actually you could do this all in regex, try

$line =~ s/\(\s*e\s*=\s*([^,]+),\)/-$1/

The regex matches the (e=num^exponent,) portion of your string and while doing that it captures the num^exponent (in $1) and then replaces the entire match with $1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜