Help with regular expression

L

leodippolito

Dear sirs,

I am trying to build a regular expression, for .NET, to check if a
string has this pattern:

{TextA-TextB}{TextC}

TextA and TextB can be of any text, but cannot contain the brackets '{'
or '}' and cannot contain the dash '-' symbol.

TextC can be of any text, including the brackets and dash symbol.

I tried some but they didn't work.

Can anyone give me a help on this?

Thanks!!
 
O

Oliver Sturm

I am trying to build a regular expression, for .NET, to check if a
string has this pattern:

{TextA-TextB}{TextC}

TextA and TextB can be of any text, but cannot contain the brackets '{'
or '}' and cannot contain the dash '-' symbol.

TextC can be of any text, including the brackets and dash symbol.

I assume you mean the {} symbols in the last sentence, which are called
curly braces (brackets usually refer to the square variant []). Obviously,
that's going to be a problem for the TextC part - if the string is
enclosed in {} and it can contain the same characters. You shouldn't allow
this, really, but it will work in my sample anyway, because the last text
match (.*) is allowed to match greedily. So, this should do it:

\{[^{}-]+-[^{}-]+\}\{.*\}



Oliver Sturm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top