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"
精彩评论