开发者

problem with regular expression

开发者 https://www.devze.com 2023-02-21 22:46 出处:网络
I need regexp for expression: \"dsfsdf|dfdfdf|Gfgfgfg|ghghfgh|fgfjghjg\" Between \"|\" may be any sequences of symbols.

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|]+

0

精彩评论

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

关注公众号