471,350 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

regex doesn't match expression

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

Sam

Jun 27 '08 #1
3 1501


<sk*****@gmail.comwrote in message
news:b2**********************************@59g2000h sb.googlegroups.com...
Hi,
I have an input string :
<NEW>g04 8/1 0<catset>pub=g04</catset>
and I use this regex expresssion to match from <NEWto </catset>, I
wrote:
<NEW>.+?</catsetbut it doesn't work, no match !
What is the good way ?
Thanks.

Sam
Depends on if you want the contents (in between NEWand </) 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
Jun 27 '08 #2
On Jun 19, 12:37 am, "Mythran" <Myth...@community.nospamwrote:
<skne...@gmail.comwrote in message

news:b2**********************************@59g2000h sb.googlegroups.com...
Hi,
I have an input string :
<NEW>g04 8/1 0<catset>pub=g04</catset>
and I use this regex expresssion to match from <NEWto </catset>, I
wrote:
<NEW>.+?</catsetbut it doesn't work, no match !
What is the good way ?
Thanks.
Sam

Depends on if you want the contents (in between NEWand </) 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
Jun 27 '08 #3
On 19 juin, 09:07, kodehoved <afk...@gmail.comwrote:
On Jun 19, 12:37 am, "Mythran" <Myth...@community.nospamwrote:
<skne...@gmail.comwrote in message
news:b2**********************************@59g2000h sb.googlegroups.com...
Hi,
I have an input string :
<NEW>g04 8/1 0<catset>pub=g04</catset>
and I use this regex expresssion to match from <NEWto </catset>, I
wrote:
<NEW>.+?</catsetbut it doesn't work, no match !
What is the good way ?
Thanks.
Sam
Depends on if you want the contents (in between NEWand </) 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
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
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sriram | last post: by
1 post views Thread by Radioflyer651 | last post: by
4 posts views Thread by Garibaldi | last post: by
5 posts views Thread by Gilles Ganault | last post: by
12 posts views Thread by cmk128 | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.