\,)\d{2,3}) It matches the following inputs perfectly: 1 XXX XXX 0,34 1 X5X XXX 0,34 My problem comes if ...

问题描述 投票:0回答:1
If you want to match that pattern and you don't need the capturing groups, you could use an optional character class

after matching a word char.

\d[\.]?[\s]?(\w+[\s]?)+\d+((\.|\,)\d{2,3})

To match them when they are not necessarily at the end, use

1 XXX XXX   0,34
1 X5X XXX   0,34

.You can omit the square brackets around the % and write

1 XX. 5 XXX 0,34
1 XXX 4% XX 0,34

as

Repeating a capturing group will capture the value of the last iteraration, so you might turn that into a non capturing group
python regex
1个回答
2
投票

Regex demo[.%]?

我正在使用这个匹配特定模式的regex。[\w.%]+它完美地匹配了以下的输入。

我的问题是,如果有一个点 [\s] 或其他特殊字符,如 (\.|\,) 喜欢[.,]

如何让regex找到这些字符?(?:

\d\s?(?:\w+[.%]?\s)+\d+[.,]\d{2,3}

\d\s?(\w+[.%]?\s)+\d+(([.,])\d{2,3})

我正在使用这种符合特定模式的regex。d/d[\\]?[\s]?(\w+[\s]?)+\d+((\。

© www.soinside.com 2019 - 2024. All rights reserved.