开发者

Need a code using regular expression in java --> String must be Captial letters(A-Z) and contain digits (0-9) [closed]

开发者 https://www.devze.com 2023-02-16 19:45 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学Go Closed 11 years ago.

I need a regular expression for:

String must be Captial letters(A-Z) and contain digits (0-9)


The following should work:

[A-Z0-9]+


^[A-Z]+[0-9]*$

Should match one or more capital letters followed by zero or more digits.

It would have been nice though if you:

-Told us exactly what you needed

-Gave us samples of what you expected

-What exactly have you tried...

Edit: If you want a regex that will match any string that has digits, capital letters AND white spaces without any particular order, then this should work:

^[A-Z0-9 ]*$

This will match 0 or more repetitions of capital letters, numbers and white spaces. If you want the string to contain at least a digit, whitespace or capital letter, then, this should do the trick:

^[A-Z0-9 ]+$

As opposed to the * operator which matches 0 or more repetitions, the + will match 1 or more. The ^ tells the regular expression to start matching from the very beginning of the string while the $ tells the regex to end the pattern matching at the very end of the string.

0

精彩评论

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