python - how to match 477xx with regular expression -


the input string must in format "477xx", x may 0-9 or whitespace, , length muse 5. want find following targets regular expression.

["477  ", "4770 ", "4771 ", "4781 "] 

how can it? rough idea: "477[0,1,8,9]?"

you can use following regex:

 ^477[0-9\s]{2}$ 

mind "4781 " not matched not start "477".

here demo.

and example code on tutorialspoint:

p = re.compile(ur'^477[0-9\s]{2}$', re.multiline) test_str = u"477  \n4770 \n4771 \n4781 " arr = re.findall(p, test_str) print  arr 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -