A
A
Alexey Burlaka2017-10-09 11:25:07
Regular Expressions
Alexey Burlaka, 2017-10-09 11:25:07

How to iterate over all pairs in a string?

Hello!
Please help me to "stick" once =)
We need to replace all pairs (sharp between numbers) in the string.
So that
8-911-1234567
8-495-1-234-zzz
... becomes this:
8|911|1234567
8|495|1|234 -zzz Tried
:
([0-9.]+)\-
== = -zzz picks up, but should not
(([0-9.]+)\-)+([0-9]+)
=== glues all sequences into one line and only splits the tail into a pair
https://regex101 .com/r/qF7vT8/63

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
display: block, 2017-10-10
@AlexeyGfi

Here, either a negative lookahead (choose a dash) /-(?![a-z])/
https://regex101.com/r/czLHsu/1/
Or in this way: /\d+(-[a-z]+)?/
https://regex101.com/r/lEEC52/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question