development of a mobile (Israeli) regex phone number. I currently have
re.compile(r'^[\(]?0?(5[023456789])\)?(\-)?\d{7}$')
which catches most use cases. the problem matches the second bracket only if the first bracket appears.
therefore, (055) -5555555 or (055) 5555555 or 0555555555 would correspond but: 055) -5555555 would not. I know that I can use 2 regular expressions to test a condition (if the first matches the test for another condition), but this does not seem like an intelligent solution.
I think I need something like a regular search, but not sure how to use it, or that I understand the concept correctly.
Edit: explanation of logic
zone code: should start with 5, and then with one digit (from a specific list) with the option zero before. it is also possible that it would be in parentheses. then an optional hyphen and 7 digits
Clarfication: I need to match both brackets only if there is another that is true and for the first not only for the second, I skipped this point
source share