473,624 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiline Regex Question

I have an expression that works for single line but not multiline. What am I missing?

expression = "<div(?<data1>. *?)>(?<data2>.* ?)</div>";
MatchCollection mc = Regex.Matches(d ata, expression,
RegexOptions.Mu ltiline |
RegexOptions.Ig noreCase |
RegexOptions.Ig norePatternWhit espace);
Expression works if data looks like this:
<div id="bodyblktx10 ">5679664</div>
Result:
data1 -=> id="bodyblktx10 "
data2 -=> 5679664

Expression DOESN'T works if data looks like this:
<div id="bodyblktx10 ">

5679664

</div>
Thanks,
Dave
Da**********@Be llSouth.net

Nov 15 '05 #1
1 8995
1) Multiline prop doesn't do what you think. It only affects eval of
^ and $

2) The default behavior of regex in matching \n with . is to __not__
be greedy, i.e. it does not consider \n to match . by default

Therefore (and oddly enough)
you want to replace RegexOptions.Mu ltiline with
RegexOptions.Si ngleline.

The official doco states

Specifies single-line mode. Changes the meaning of the period
character (.) so that it matches every character (instead of every
character except \n).

David Elliott <Da**********@B ellSouth.net> wrote in message news:<ll******* *************** **********@4ax. com>...
I have an expression that works for single line but not multiline. What am I missing?

expression = "<div(?<data1>. *?)>(?<data2>.* ?)</div>";
MatchCollection mc = Regex.Matches(d ata, expression,
RegexOptions.Mu ltiline |
RegexOptions.Ig noreCase |
RegexOptions.Ig norePatternWhit espace);
Expression works if data looks like this:
<div id="bodyblktx10 ">5679664</div>
Result:
data1 -=> id="bodyblktx10 "
data2 -=> 5679664

Expression DOESN'T works if data looks like this:
<div id="bodyblktx10 ">

5679664

</div>
Thanks,
Dave
Da**********@Be llSouth.net

Nov 15 '05 #2

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

Similar topics

0
1582
by: sinasalek | last post by:
i have a problem below code : <?php $text=' <html dir="rtl"> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html;
1
7396
by: Laser Lu | last post by:
Hi, all, I'm now writing a program to compress JavaScript code. One puzzle is how to write a regular expression to find out and remove all the redundent blank spaces. However, those blank spaces that are in the comments should be kept intact. I've tried to write some Regexs, and I list them here for your information: regex = new Regex(@"/\**?\*/"); // pattern used to match a multiline comment block regex = new Regex(@"//*\n"); //...
0
346
by: Stephan Bour | last post by:
Follow up to previous question: I¹m trying to validate a multipline asp text box that can have a maximum of 150 word characters but any number of white space, carriage returns or tabs. I tried several regex that pass testing on regexplib.com but fail on the page This for example doesn¹t work properly: ValidationExpression="^\w{1,150}|\s{0,}$" I get a validation error if any non-word character is added, regardless of
0
1095
by: GenoJoe | last post by:
I thought I understood this topic rather well until I ran the following procedure Private Sub Tes Dim oMatch As Matc Dim oMC As MatchCollection = Regex.Matches("abc" & vbCrLf & "abc", "abc$", RegexOptions.Multiline For Each oMatch In oM Console.WriteLine(oMatch.ToString Nex oMC = Regex.Matches("def" & vbCrLf & "def", "^def", RegexOptions.Multiline For Each oMatch In oM
2
4392
by: Allen | last post by:
In regex, ^ and $ shoudl match start/end of a line when the 'm' /multiline modifier is set -- however I just spent the better part of the day trying to figure out why it wasn't working as expected. I used the query test$ ....and the text test test test Only the last instance of test would match -- that is expected without the
1
1666
by: shuiqing.li | last post by:
Hi, I met a question when I would match some lines using the pattern "<td>(.*?)</td>" in flows : =============== <td>Hi hello world! .... </td> ===============
3
2278
by: Masa Ito | last post by:
I am trying to capture the contents of a function with Regex. I am using Expresso to test (nice - thanks for the great tool UltraPico!). I can handle my own with single line regex's (I think).. I want to have a named capture of the entire 'contents' of specific functions. EG: Sample code <Description("{0} is a required field.")_ Protected Overridable Function AccountIDRequired(ByVal target As Object, ByVal e As RuleArgs) As Boolean...
3
2016
by: ommail | last post by:
Hi! I have a simple regural expression: \w+$ and text to match: abc dddd ggg hhh
5
1855
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 = "<b>Bla</b>blabla<font color=#123>"
0
8246
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8685
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...
1
8341
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
8490
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...
1
6112
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
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
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
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2612
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.