开发者

Get the word after matching certain Expression

I am trying to开发者_StackOverflow社区 get the word "1.23" from this string.

The String is

"1 USD in SGD 1.23".

I know regex can find words but I want to get the number after the SGD which is "1.23".

Thanks.


The regex could be something like: \bSGD\s+(\d+(?:\.\d+)?), but what works with grep I'm not sure.

With perl you could do grep-like stuff:

cat foo.txt | perl -n -e '/\bSGD\s+(\d+(?:\.\d+)?)/ && print "$1\n"'


Works with -P (for Perl regular expression) :

grep -P "(?<=\bSGD)\s*1\.23"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜