1

I need regexp for expression: "dsfsdf|dfdfdf|Gfgfgfg|ghghfgh|fgfjghjg" Between "|" may be any sequences of symbols.

I have tried 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...

2
  • What exactly do you want to achieve? To split the string or just test it against the pattern? Commented Apr 5, 2011 at 10:07
  • just test it against the pattern Commented Apr 5, 2011 at 10:10

3 Answers 3

2

I think you need the next expression:

^[^|].*[^|]$

it matches a string if it isn't begins or ends with the | symbol.

Sign up to request clarification or add additional context in comments.

Comments

0

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 _ )

2 Comments

Your solution finds expression like this: "qweqe|qw|eqwerer|" too, but i need "|" only in middle.
Then I am sure there is a solution using a lookahead assertion (I am sorry, not getting it to work at the moment), but this is also a complex expression. I think your expression [a-z]+\|[a-z]+ is then easier to read. And I would not name it copy-paste what you are doing here, you are describing your pattern.
0

Why not just use string.Split('|')?

If you want to verify that your string is valid use [a-z|]+

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.