problem with regular expression
I need regexp for expression: "dsfsdf|dfdfdf|Gfgfgfg|ghghfgh|fgfjghjg
"
Between "|" may be any sequences of symbols.
I have trie开发者_JAVA百科d this expression: [a-z]+\|[a-z]+
but it contains similar code ([a-z]+). I want expression without copy-paste because in fact my expression is more complex.
Thanks in advance...
I think you need the next expression:
^[^|].*[^|]$
it matches a string if it isn't begins or ends with the |
symbol.
Try
(?:[A-Za-z]+\|?)+
The (?:)
is a non capturing group and the \|?
is looking for one or 0 |
You can add any character you are looking for between the []
. There are also predefined character sets like \w
for word characters (I am not sure what is defined as a word character within c# .net at least A-Za-z and _ )
Why not just use string.Split('|')
?
If you want to verify that your string is valid use [a-z|]+
精彩评论