开发者

Regular expression so that only 'a','A','p' and 'P' can be entered as input

开发者 https://www.devze.com 2023-03-11 10:00 出处:网络
Can anyone please tell me regular expression so that only \'a\',\'A\',\'p\' and \'P\' can be entered as input and at a time only one of those character shoul开发者_如何转开发d be entered?

Can anyone please tell me regular expression so that only 'a','A','p' and 'P' can be entered as input and at a time only one of those character shoul开发者_如何转开发d be entered?

Thanks in advance.


Here's a simple one: [aApP]

Does that work for you?

You might have to add language-specific start & end line symbols, e.g. ^[aApP]$ if you want to check that the entire input consists only of that one character.


Assuming you want either upper or lowercase p:

[aApP]


^[aApP]{1}$ will match a single 'a', 'A', 'p', or 'P'.
^[aApP]+$ will match one or more 'a', 'A', 'p', or 'P'.


[aApP] if you only want to match a single character.

^[aApP]+$ to match aa, PaP, but not ab.

0

精彩评论

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