search

Home  >  Q&A  >  body text

javascript - optimization of a regular expression

Matches the integer of 1024-65535, that is, 65535 >= x >= 1024. Use regular rules to write it. Mine is
/^(102[4-9]|10[3-9]d {1}|1[1-9]d{2}|[2-9]d{3}|[1-5]d{4}|6[0-4]d{3}|65[0- 4]d{2}|655[0-2]d{1}|6553[0-5])$/
Is there a more concise and optimized way of writing

伊谢尔伦伊谢尔伦2775 days ago596

reply all(4)I'll reply

  • 高洛峰

    高洛峰2017-05-19 10:11:54

    What's going on? I feel like it's easier to convert this thing into a number and then convert it into a string... I don't know your specific situation

    reply
    0
  • 某草草

    某草草2017-05-19 10:11:54

    First subtract 1024 from the number you got and then do the matching. It will be a little simpler d{1,4}|[1-5]d{4}|6[1-3]d{3}|64[1-4]d{2}|6450d|6451[01]
    Standing for the answers from all the heroes

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:11:54

    /^(6[0-4]d{3}|65[0-4]d{2}|655[0-2]d|6553[0-5]d|[1-5]d{4}|[2-9]d{3}|1d[3-9]d|102[4-9])$/

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-19 10:11:54

    Why not just compare the sizes directly. . .

    reply
    0
  • Cancelreply