开发者

Help needed with Java Regular Expression

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜