I'm creating a Regex in Python where I need to find a blank spaces in a string
Example
000#0123456789#ASimpleName#123456 000#987654321#OtherSimpleName#8765432
000#0123456789#ASimpleName#EUA 000#987654321#OtherSimpleName#8765432
In this case, if I use re.split('\\s'
) I solve my problem, but I can find this
000#0123456789#A simple Name#123456 000#987654321#Other Simple Name#8765432
000#0123456789#ASimpleName#EUA 000#987654321#OtherSimpleName#8765432
I've tried to use this expression [\\d|\\w]\\s\\d
, but the Regex get 6 0
and A 0
, but I need only the blank space.
You may use the following regex with re.split
:
\s+(?=000#)
Or, if there may be any 3 digits:
\s+(?=\d{3}#)
See the regex demo and the https://jex.im/regulex diagrams:
Details
\\s+
- matches and consumes 1 or more whitespace chars (?=\\d{3}#)
- makes sure that, immediately to the right of the current location, there are 3 digits followed with #
. (?=000#)
returns true only if the three digits are zeros. #
may not be necessary here, but that depends on the actual data and requirements.
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.