开发者

Get the word after matching certain Expression

开发者 https://www.devze.com 2023-03-12 20:21 出处:网络
I am trying to开发者_StackOverflow社区 get the word \"1.23\" from this string. The String is \"1 USD in SGD 1.23\".

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

精彩评论

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