我想根据标题中列出的参数拆分一个字符串.我try 了一些不同的方法,包括使用preg_match,但迄今为止没有太大成功,我觉得可能有一个更简单的解决方案,我还没有想到.
我有一个与标题中提到的"价格"匹配的正则表达式(见下文).
/(?=.)\£(([1-9][0-9]{0,2}(,[0-9]{3})*)|[0-9]+)?(\.[0-9]{1,2})?/
以下是一些示例场景,以及我期望的结果:
例1:
input: "This string should not split as the only periods that appear are here £19.99 and also at the end."
output: n/a
例2:
input: "This string should split right here. As the period is not part of a price or at the end of the string."
output: "This string should split right here"
例3:
input: "There is a price in this string £19.99, but it should only split at this point. As I want it to ignore periods in a price"
output: "There is a price in this string £19.99, but it should only split at this point"