开发者

Help needed with Java Regular Expression

开发者 https://www.devze.com 2023-03-17 19:35 出处:网络
I need to create a regular expression that allows a string to optionally contain an asterisk as its first or last character, or both. The string can contain no more than two asterisks and those asteri

I need to create a regular expression that allows a string to optionally contain an asterisk as its first or last character, or both. The string can contain no more than two asterisks and those asterisks must be at the start and/or end of the string.

So these strings would be valid:

foo
*foo
foo*
*foo*

and these strings would not:

*
**
**foo
*f*oo
*f*o*开发者_如何学运维o
*f*o*o*

Thanks in advance.


This should do what you're asking

^\\*?[^*]+\\*?$

Help needed with Java Regular Expression

0

精彩评论

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