简体   繁体   中英

Python Anchors to validate specific characters in beginning and in the end

My example text is

A 12324567#JAIEKLLIMdata B

and trying to extract string which begins with A and ends with B

my regex is

"\AA [A-Za-z0-9]\ZB"

or

"^A[A-Za-z0-9]B$"

I get a no match found when trying run this regex. Any suggestions where i am going wrong?

Your second regex almost works, but it only works if the string is exactly three characters long. Try

"^A[A-Za-z0-9 #]*B$"

(you also need to include # and space in the character class).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM