I'm trying to write a regular expression in order to cover all numbers starting with 1809 and excluding some ranges:

Ranges needed to be excluded

Starting with 1809 and followed by:

  • 201,203,205,212,214,222,228,232,235,249,256,260,2643983
  • 266,2724728,2725724,299,315,330,350-354,356-361,3670229
  • 370,383,386,389,391,394-399,401-411,413,424-429,451-469
  • 477-481,484,485,488,490-499,501,502,504-507,509,510,512
  • 514,516,517,519,520,543,545,606,615,618,661-668,670-675
  • 694,696-698,7079832,710,720-722,727,729,744,747,749-753
  • 756-765,767,769,773,774,778,7837079,7839522,792-799,809
  • 823-826,828,830-832,834-844,895-898,950,953
  • 1
    It would be much better if you introduce the example of raw strings. – Costas Nov 17 '14 at 10:32
  • For example the below range need to be excluded from all numbers started with 1809 (^1809 without the following RE): ^1809(20[135]|21[24]|22[28]|23[25]|24[9]|256|26[06]|2643983|27247) – Charles nakhel Nov 17 '14 at 10:37
  • May be list of numbers to be included much shorter or easy for grupping? – Costas Nov 17 '14 at 10:43
  • 4
    Maybe regex is not the right tool for this job. What are you really trying to do? – PM 2Ring Nov 17 '14 at 10:56
  • I will use this for an application to control a traffic, the destination will be just numbers thus the only one solution i have is to write a regular expression that match everything start with 1809 and remove the above list from it (the big list of numbers could be modified any time)... 1809 or the list of number means nothing it is just an example. The idea here is how to exclude numbers using regex... – Charles nakhel Nov 17 '14 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.