I need to extract two phone numbers from a string with delimiters (tilde). The tricky part is the format of the phone numbers can vary.
The string pattern stays the same
You may use
(?<=~\+|~)([0-9]+)(?=~)
See the regex demo
If there is a problem with lookbehind, use a bit modified variant:
(?:(?<=~\+)|(?<=~))([0-9]+)(?=~)
Details
(?<=~\+|~)
- there must be ~+
or ~
immediately to the left of the current location([0-9]+)
- Group 1: one or more digits(?=~)
- there must be ~
immediately to the right of the current location.