473,786 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regular Expressions Multiple Lines

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(s Text, sRegex,
RegexOptions.Si ngleline);

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.
Nov 15 '05 #1
5 12081
..+

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******@hotma il.com> wrote in message
news:1d******** *************** ***@posting.goo gle.com...
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(s Text, sRegex,
RegexOptions.Si ngleline);

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.

Nov 15 '05 #2
and dont forget to use the RegexOptions.Mu ltiline 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******** ******@TK2MSFTN GP11.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******@hotma il.com> wrote in message
news:1d******** *************** ***@posting.goo gle.com...
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(s Text, sRegex,
RegexOptions.Si ngleline);

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.


Nov 15 '05 #3
I could be wrong, but I thought I wanted the RegexOption.Sin gleline
set so .+ will match every line. What would having the
RegexOption.Mul tiline 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.
Nov 15 '05 #4
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******@hotma il.com> wrote in message
news:1d******** *************** ***@posting.goo gle.com...
I could be wrong, but I thought I wanted the RegexOption.Sin gleline
set so .+ will match every line. What would having the
RegexOption.Mul tiline 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.

Nov 15 '05 #5
Hi,
[inline]
"Jeremy R. Harner" <jr******@hotma il.com> wrote in message
news:1d******** *************** ***@posting.goo gle.com...
I could be wrong, but I thought I wanted the RegexOption.Sin gleline
set so .+ will match every line. What would having the
RegexOption.Mul tiline 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.

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4184
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 regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
15
434
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 (a-z or A-Z) No special characters allowed except for full stop. I am struggling to get to grips with regular expressions. Can anyone
7
2191
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. Consider the example of the HTML element TABLE with the following attributes producing sufficient complexity within the element: <table id="machines" class="noborders inred" style="margin:2em 4em;background-color:#ddd;">
3
1413
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 ... other lines of code ...
10
2891
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
4
339
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 may not be empty) - The data lenght must be between 1 to 255. - The user may add data on multiple lines. (some lines may be left empty) - The data is not case-sententive.
4
5187
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 adate LIKE "2004.01.10 __:15") .... into something like this: .... where adate LIKE "2004.01.10 __:(30/15)" ...
2
5349
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 2,"3","000000000691","000007","65Xbp5dMcDFflPJnxWCrsJtV1jzcUjgd","BAR","0010","","",20.00 3,"3","000000000692","000007","SEjcf3eDA7hWmwGrNsLWoCWt1Geyh4GN","BAR","0010","","",20.00 4,"3","000000000693","000007","MJMkrp/kRMMGimeZo1uFOJzeDTVeOkFU","BAR","0010","","",20.00...
5
8785
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 them. An example: mikko.c: ----- #include <stdio.h> #include <regex.h>
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9962
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8992
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7515
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.