regex doesn't match expression

  • Thread starter Thread starter skneife
  • Start date Start date
S

skneife

Hi,
I have an input string :
<NEW>g04 8/1 0<catset>pub=g04</catset>
and I use this regex expresssion to match from <NEW> to </catset>, I
wrote:
<NEW>.+?</catset> but it doesn't work, no match !
What is the good way ?
Thanks.

Sam
 
Hi,
I have an input string :
<NEW>g04 8/1 0<catset>pub=g04</catset>
and I use this regex expresssion to match from <NEW> to </catset>, I
wrote:
<NEW>.+?</catset> but it doesn't work, no match !
What is the good way ?
Thanks.

Sam

Depends on if you want the contents (in between NEW> and </) or match the
tags as well? Do you want captures?

Here are a couple of solutions:

Solution #1: this is a full match of what you asked for....
\<NEW\>.@\</catset\>

Solution #2: this is a full match with 2 captures. If you would like to see
the reason for this, use the Replace with text in the Quick Replace dialog:

Find expression:
\<NEW\>{.*}\<catset\>{.*}\</catset\>

Replace with expression:
NEW: "\1"\nCATSET: "\2"

Do either of these find expressions solve your problem?

HTH,
Mythran
 
Depends on if you want the contents (in between NEW> and </) or match the
tags as well? Do you want captures?

Here are a couple of solutions:

Solution #1: this is a full match of what you asked for....
\<NEW\>.@\</catset\>

Solution #2: this is a full match with 2 captures. If you would like to see
the reason for this, use the Replace with text in the Quick Replace dialog:

Find expression:
\<NEW\>{.*}\<catset\>{.*}\</catset\>

Replace with expression:
NEW: "\1"\nCATSET: "\2"

Do either of these find expressions solve your problem?

HTH,
Mythran

I'm not sure what the problem is. The following prints "found"

string s = "<NEW>g04 8/1 0<catset>pub=g04</catset>";
if (Regex.IsMatch(s, "<NEW>.+?</catset>")) {
Console.WriteLine("found");
}

Brian
 
I'm not sure what the problem is. The following prints "found"

string s = "<NEW>g04 8/1 0<catset>pub=g04</catset>";
if (Regex.IsMatch(s, "<NEW>.+?</catset>")) {
Console.WriteLine("found");
}

Brian

Yes Brian you are right, my sample code match the searched string.
I was using a tool for testing and it was not work for a unknown
reason.
Thanks for help.
Sam
 

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

Back
Top