简体   繁体   English

python 重新字符串开头

[英]python re string starting with

In the following string how to say that the line is starting with a digit or ending with a number or many在以下字符串中,如何表示该行以数字开头或以数字或多个结尾

line="He is a German called Mayer12345"
re.compile(r".*\d+\w$")

line="12He is a German called Mayer"
re.compile(r"^\d+\w .*")

Just use the pipe, it's an or for regexes:只需使用 pipe,它是一个或用于正则表达式:

re.compile(r"(^\d+\w .*)|(.*\d+\w$)")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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