Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

javascript - how to match uncertain numbers without special words before them with js regular expression

For Example. I want to get the numbers without 'the' or 'abc' or 'he' before them;

  1. the89 (no match)

  2. thisis90 (match 90)

  3. iknow89999 (match 89999)

  4. getthe984754 (no match)

  5. abc58934(no match)

  6. he759394 (no match)

I try to use this (?<!(the|abc|he))[0-9]+ , but failed


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You may use this regex with negative lookbehind:

(?<!t?he|abc|d)d+

RegEx Demo

RegEx Details:

  • (?<!: Start negative lookbehind, to fail when we get any of:
    • t?he: the or he
    • |: OR
    • abc: abc
    • |: OR
    • d: a digit
  • ): End negative lookbehind
  • d+: Match 1+ digits

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...