[英]Regex match value prefixed/suffixed by currency symbol/code
I need a regex to match & extract a decimal value prefixed (or suffixed) by its currency. 我需要一个正则表达式来匹配并提取以其货币为前缀(或后缀)的十进制值。 Here are some examples
这里有些例子
10$
10.01 $
$ 10.012
61 USD
£ 50.51
94 GBP
Found this \\p{Sc} very useful, but insufficient for what i need. 发现此\\ p {Sc}非常有用,但不足以满足我的需求。
怎么样:
((?:\p{Sc}|[A-Z]{3})?\s*\d+(?:\.\d+)?\s*(?:\p{Sc}|[A-Z]{3})?)
This regex should work on PCRE regex engines (since it is using branch reset feature ): 此正则表达式应在PCRE正则表达式引擎上工作(因为它正在使用branch reset功能 ):
(?|(\p{Sc}|USD|GBP) *(\d+(?:\.\d+)?)|(\d+(?:\.\d+)?) *(\p{Sc}|USD|GBP))
This produces following MATCH
information for your input data: 这将为您的输入数据生成以下
MATCH
信息:
MATCH 1
1. 10
2. $
MATCH 2
1. 10.01
2. $
MATCH 3
1. $
2. 10.012
MATCH 4
1. 61
2. USD
MATCH 5
1. £
2. 50.51
MATCH 6
1. 94
2. GBP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.