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
^\\*?[^*]+\\*?$
精彩评论