Home > front end >  How to use regex in python to catch patterns like keyword1 [arbitrary characters with a max length o
How to use regex in python to catch patterns like keyword1 [arbitrary characters with a max length o

Time:09-26

How can I use re package to recognize a pattern as

keyword1 [arbitrary characters with a max length of 5] keyword2

For example, keyword1 abc keyword2 is valid, keyword1 a . keyword2 is also valid but keyword1 1234abd keyword2 is not valid

Thank you

CodePudding user response:

r"(?:keyword1).{5}(?:keyword2)

Checked this on https://regex101.com/

  • Related