0

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
5
  • 1
    It would be much better if you introduce the example of raw strings.
    – Costas
    Nov 17, 2014 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) Nov 17, 2014 at 10:37
  • May be list of numbers to be included much shorter or easy for grupping?
    – Costas
    Nov 17, 2014 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, 2014 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... Nov 17, 2014 at 11:17

1 Answer 1

1

I manually wrote the regex which matches all patterns you want excluded:

/1809(20[135]|21[24]|22[28]|23[25]|249|256|26[06]|2643983|2724728|2725724|299|315|330|35[0-46-9]|36[01]|3670229|370|38[369]|39[14-9]|40[1-9]|41[013]|42[4-9]|45[1-9]|46[0-9]|47[7-9]|48[01458]|49[0-9]|50[124-79]|51[024679]|520|54[35]|606|61[58]|66[1-8]|67[0-5]|69[46-8]|7079832|710|72[0-279]|74[479]|75[0-36-9]|76[0-579]|77[348]|7837079|7839522|79[2-9]|809|82[3-68]|83[0-24-9]|84[0-4]|89[5-8]|95[03])/

I'm not sure how you would automatically generate this regular expression given the above information though.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .