473,394 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1566


<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sriram | last post by:
Hi, I am having trouble matching a regex that combines a negated character class and an anchor ($). Basically, I want to match all strings that don't end in a digit. So I tried: ...
5
by: Aaron C | last post by:
Hi, I'm trying to do an insert with the following statement: INSERT INTO user VALUES ( 'ag@ag.com','ag','Aaron','Chandler','','','La Mirada','CA',90638,714,'',''); and I'm getting the error...
1
by: Radioflyer651 | last post by:
I'm stumped... I'm trying to find start and stop blocks in a string which use the same markers. The problem is that it finds the very first start marker and very last end marker and counts only...
4
by: Garibaldi | last post by:
Folks, I'm having a bad regex day and can sure use your help, please.. I have a Regex expression that works fine. It's purpose is to isolate all data from the start of a string begining with...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
4
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
5
by: Gilles Ganault | last post by:
Hello I'm trying to extract information from a web page using the Re module, but it doesn't seem to support MULTILINE: ============= import re #NO CRLF : works response =...
12
by: cmk128 | last post by:
Hi PHP's regular expression look like doesn't support .*? syntax. So i cannot match the shortest match. For exmaple: $str="a1b a3b"; $str1=ereg_replace("a.*b", "peter", $str1); will produce...
3
by: mkjame | last post by:
Hi everyone! I am actually coding a php script and I want to return all the values that doesn't have a relation between two tables. Basically I have two tables, one is called users, the other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.