开发者

Regex matching "four characters, followed by an unknown No of digits."

An example of how the S开发者_如何学运维trings may look:

TADE000177
TADE007,daFG
TADE0277 DFDFG


It's a little unclear what you want.

If you mean four capital letters from A to Z, followed by at least one digit in 0-9 you could try this:

"^[A-Z]{4}[0-9]+"
  • If instead of capital letters you want to allow any character except newline change [A-Z] to ..
  • If you want to also allow zero digits change the + to a *.


Exactly four characters followed by 1 or more digits: [A-Z]{4}\d+

Remember to escape the backslash if you put it in a string literal.

Breakdown:

  • [A-Z]…: An upper case letter, equivalent to \p{Upper}
    • To also include lower case letters, you could instead use [A-Za-z] or \p{Alpha}
  • …{4}… exactly 4 times
  • …\d…+ a digit
  • …+ 1 or more times
    • To allow 0 digits, you could change to *.


If i understood correctly what you're asking for you can try: .{4}\d*


^\w{4}.*$

Matches a string starting with 4 characters followed by any number of any other charcters. Your examples include spaces and punctuation, if you know exactly which characters are allowed then you might want to use this pattern.

^\w{4}[A-z\d<other known characters go here>]*$

Remember to remove the < and > too :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜