简体   繁体   中英

python regular expression repeating pattern match

I would like some thoughts on how to write a regular expression which validates a pattern

ex. .??2

one of more characters followed by two question marks followed by one or more numbers and if only if there is another repeating pattern then the seperator will be a semi colon.

more examples

--??9;.??50;,??3 - in this example I have the pattern repeating and that is why the semi colon

or

*??5 - a * followed by two qnestions marks followed by a number and no semi colon as there are no repeating groups

This is what i currently have

.+\\?\\?\\d+(;|)+

The basic pattern is .+?\\?\\?\\d+ . We have made the first .+ non-greedy so it won't try to match the whole string right away. Use a repeated group to capture the subsequent patterns: r'(.+?\\?\\?\\d+)(;.+?\\?\\?\\d+)*'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM