473,387 Members | 1,553 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,387 software developers and data experts.

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(data, expression,
RegexOptions.Multiline |
RegexOptions.IgnoreCase |
RegexOptions.IgnorePatternWhitespace);
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**********@BellSouth.net

Nov 15 '05 #1
1 8953
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.Multiline with
RegexOptions.Singleline.

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**********@BellSouth.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(data, expression,
RegexOptions.Multiline |
RegexOptions.IgnoreCase |
RegexOptions.IgnorePatternWhitespace);
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**********@BellSouth.net

Nov 15 '05 #2

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

Similar topics

0
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
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...
0
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...
0
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$",...
2
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....
1
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
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).. ...
3
by: ommail | last post by:
Hi! I have a simple regural expression: \w+$ and text to match: abc dddd ggg hhh
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 =...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.