I've been trying to figure out this for many hours now. I have a file
that is in the following format:
Game #xxxxxxxxx
stuff
stuff
stuff
stuff
stuff
-----------------------------
Game #xxxxxxxxx
stuff
stuff
stuff
-----------------------------
Game #xxxxxxxxx
stuff
stuff
stuff
stuff
-----------------------------
Here is my code:
//Match from 'Game # to ----------------------------- so includes all
the stuff.
string sRegex = @"Game\s#\.+-----------------------------";
MatchCollection theMatches = Regex.Matches(sText, sRegex,
RegexOptions.Singleline);
where, sText is the above text.
I then want to do:
foreach( Match m in theMatches)
{
string s = m.ToString();
//Do other text parsing
}
I want there to be three matches. So that the string s contains
everything from Game to the line of hyphens (------------------). But
this regex finds only one match and it is the entire string all three
segments. Any ideas on what a regular expression that would work. 5 12055
..+
matches as many characters as possible. Try using a non-greedy match
instead:
..+?
--
Eric Gunnerson
Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jeremy R. Harner" <jr******@hotmail.com> wrote in message
news:1d**************************@posting.google.c om... I've been trying to figure out this for many hours now. I have a file that is in the following format:
Game #xxxxxxxxx stuff stuff stuff stuff stuff ----------------------------- Game #xxxxxxxxx stuff stuff stuff ----------------------------- Game #xxxxxxxxx stuff stuff stuff stuff -----------------------------
Here is my code:
//Match from 'Game # to ----------------------------- so includes all the stuff. string sRegex = @"Game\s#\.+-----------------------------";
MatchCollection theMatches = Regex.Matches(sText, sRegex, RegexOptions.Singleline);
where, sText is the above text.
I then want to do:
foreach( Match m in theMatches) { string s = m.ToString(); //Do other text parsing }
I want there to be three matches. So that the string s contains everything from Game to the line of hyphens (------------------). But this regex finds only one match and it is the entire string all three segments. Any ideas on what a regular expression that would work.
and dont forget to use the RegexOptions.Multiline flag so that [.*] will
match newline characters
--
Eric Newton
C#/ASP Application Developer http://ensoft-software.com/ er**@cc.ensoft-software.com [remove the first "CC."]
"Eric Gunnerson [MS]" <er****@online.microsoft.com> wrote in message
news:eY**************@TK2MSFTNGP11.phx.gbl... .+
matches as many characters as possible. Try using a non-greedy match instead:
.+?
-- Eric Gunnerson
Visit the C# product team at http://www.csharp.net Eric's blog is at http://blogs.gotdotnet.com/ericgu/
This posting is provided "AS IS" with no warranties, and confers no
rights. "Jeremy R. Harner" <jr******@hotmail.com> wrote in message news:1d**************************@posting.google.c om... I've been trying to figure out this for many hours now. I have a file that is in the following format:
Game #xxxxxxxxx stuff stuff stuff stuff stuff ----------------------------- Game #xxxxxxxxx stuff stuff stuff ----------------------------- Game #xxxxxxxxx stuff stuff stuff stuff -----------------------------
Here is my code:
//Match from 'Game # to ----------------------------- so includes all the stuff. string sRegex = @"Game\s#\.+-----------------------------";
MatchCollection theMatches = Regex.Matches(sText, sRegex, RegexOptions.Singleline);
where, sText is the above text.
I then want to do:
foreach( Match m in theMatches) { string s = m.ToString(); //Do other text parsing }
I want there to be three matches. So that the string s contains everything from Game to the line of hyphens (------------------). But this regex finds only one match and it is the entire string all three segments. Any ideas on what a regular expression that would work.
I could be wrong, but I thought I wanted the RegexOption.Singleline
set so .+ will match every line. What would having the
RegexOption.Multiline option do. The documentation says:
Singleline Specifies single-line mode.
Changes the meaning of the dot (.) so it matches every character
(instead of every character except\n).
I tried this regular expression:
@"Game\s#.*?--------------" but it still returns no matches. Again i
have the SingleLine option set.
because the . in SingleLine mode will NOT match newline characters... what
i'm saying is it seems like you actually DO want the Multiline set...
"Jeremy R. Harner" <jr******@hotmail.com> wrote in message
news:1d**************************@posting.google.c om... I could be wrong, but I thought I wanted the RegexOption.Singleline set so .+ will match every line. What would having the RegexOption.Multiline option do. The documentation says:
Singleline Specifies single-line mode.
Changes the meaning of the dot (.) so it matches every character (instead of every character except\n).
I tried this regular expression:
@"Game\s#.*?--------------" but it still returns no matches. Again i have the SingleLine option set.
Hi,
[inline]
"Jeremy R. Harner" <jr******@hotmail.com> wrote in message
news:1d**************************@posting.google.c om... I could be wrong, but I thought I wanted the RegexOption.Singleline set so .+ will match every line. What would having the RegexOption.Multiline option do. The documentation says:
Singleline Specifies single-line mode.
Changes the meaning of the dot (.) so it matches every character (instead of every character except\n).
I tried this regular expression:
@"Game\s#.*?--------------" but it still returns no matches. Again i
Are you sure you output each matched string because this should work fine.
The syntax is good and you use the SingleLine option, which is a must.
(Multiline option isn't required, it changes the behaviour of $^ so that it
matches every line instead of the whole text)
HTH
greetings
have the SingleLine option set. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kenneth McDonald |
last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate
feedback, suggestions, and criticism as I work towards finalizing the
API and feature sets. rex is a module intended to make...
|
by: Roz Lee |
last post by:
I am trying to work out a regular expression which will validate a
password box.
The following rules apply
Must be 8 characters
Must have at least one digit (0-9) and at least one character...
|
by: Patient Guy |
last post by:
Coding patterns for regular expressions is completely unintuitive, as far
as I can see. I have been trying to write script that produces an array
of attribute components within an HTML element.
...
|
by: Gianluca |
last post by:
Hi,
I'm using regular expressions to extract some information from my
vb.net source code files.
I have something like this:
1: '<class name="xyz" description="xxxxxx"/>
2: Class xyz
......
|
by: hclugano |
last post by:
Hi!
There is a SQL Create Table statement, for example:
CREATE TABLE . (
IDENTITY (1, 1) NOT NULL,
NOT NULL,
( 15) NOT NULL
.....
) ON
|
by: Arjen |
last post by:
Hi,
I need some regular expressions but don't know how to create them.
If somebody knows a good, easy to use, readable tool. Please tell me.
I have a textbox.
- The user must enter data. (it...
|
by: Együd Csaba |
last post by:
Hi All,
I'd like to "compress" the following two filter expressions into one -
assuming that it makes sense regarding query execution performance.
.... where (adate LIKE "2004.01.10 __:30" or...
|
by: Sathyaish |
last post by:
I have a CSV file like so:
"HDR",20060629133932,"9845","9083","0010"
1,"3","000000000690","000007","rsM4hJXR5Ik0O8RWghjtDBlUVAOZq7tO","BAR","0010","","",20.00...
|
by: mikko.n |
last post by:
I have recently been experimenting with GNU C library regular
expression functions and noticed a problem with pattern matching. It
seems to recognize only the first match but ignoring the rest of...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |