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

Problem with Regular Expressions in .NET

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 ...
y: End Class

I want to extract with regular expression a string that contains the
file from line 1 to line y. To do this I use the following regular
expression pattern:

'\s*<class.*End\s+Class

But it doesn't work, it returns zero matches. I tried to set the
IgnoreCase flag, the MultiLine flag, but there is nothing to do. Note
that if I use the following pattern:

'\s*<class.*/>

to extract only line 1 it works.
So it seems that the .* (It should match all characters between
'<Class and End Class) doesn't work when there are multiple lines.

What can I do?

Thanks in advance for the help.

Bye

Gianluca
Nov 16 '05 #1
3 1397
1. You need the Singleline-Flag, or the '.' character won't match newlines
2. Use something like: "\bclass\b.*\bEnd\s+Class\b" "\b" ensures word
boundary
3. This won't work with nested classes, or more than one class in per file
4. This won't recognize comments or strings - If your code contains a string
literal "end class" or a comment ' end class, the regex will think this is
the end of the class.

Correct handling of these cases is possible, but quite complex: If you need
this, maybe a parsing the file line-by-line would be easier.

Niki

"Gianluca" <mo**********@hotmail.com> wrote in
news:56**************************@posting.google.c om...
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 ...
y: End Class

I want to extract with regular expression a string that contains the
file from line 1 to line y. To do this I use the following regular
expression pattern:

'\s*<class.*End\s+Class

But it doesn't work, it returns zero matches. I tried to set the
IgnoreCase flag, the MultiLine flag, but there is nothing to do. Note
that if I use the following pattern:

'\s*<class.*/>

to extract only line 1 it works.
So it seems that the .* (It should match all characters between
'<Class and End Class) doesn't work when there are multiple lines.

What can I do?

Thanks in advance for the help.

Bye

Gianluca

Nov 16 '05 #2
Niki,

I wrote 10 minutes ago in the general group I did not see messages from you
some days, a mistake I see.

Cor
Nov 16 '05 #3
"Niki Estner" <ni*********@cube.net> wrote in message news:<#6*************@TK2MSFTNGP09.phx.gbl>...

You are right, setting the Singleline flag it works.
I thought that this flag was the default, that is the reason why I
didn't tried this flag before.

Thanks for your suggestions.

Bye

Gianluca

1. You need the Singleline-Flag, or the '.' character won't match newlines
2. Use something like: "\bclass\b.*\bEnd\s+Class\b" "\b" ensures word
boundary
3. This won't work with nested classes, or more than one class in per file
4. This won't recognize comments or strings - If your code contains a string
literal "end class" or a comment ' end class, the regex will think this is
the end of the class.

Correct handling of these cases is possible, but quite complex: If you need
this, maybe a parsing the file line-by-line would be easier.

Niki

"Gianluca" <mo**********@hotmail.com> wrote in
news:56**************************@posting.google.c om...
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 ...
y: End Class

I want to extract with regular expression a string that contains the
file from line 1 to line y. To do this I use the following regular
expression pattern:

'\s*<class.*End\s+Class

But it doesn't work, it returns zero matches. I tried to set the
IgnoreCase flag, the MultiLine flag, but there is nothing to do. Note
that if I use the following pattern:

'\s*<class.*/>

to extract only line 1 it works.
So it seems that the .* (It should match all characters between
'<Class and End Class) doesn't work when there are multiple lines.

What can I do?

Thanks in advance for the help.

Bye

Gianluca

Nov 16 '05 #4

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

Similar topics

1
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...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
5
by: Greg Vereschagin | last post by:
I'm trying to figure out a regular expression that will match the innermost tag and the contents in between. Specifically, the string that I am attempting to match looks as follows: ...
5
by: Kijak | last post by:
Hi, Im just starting working with REGEX and got a few problems. Could you tell me how to test if two strings can be found in another. ei: String to test: "This is a great car you got" Look...
4
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...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
4
by: =?Utf-8?B?Y3VyaW91cw==?= | last post by:
I am using a RegularExpressionValidator to validate a TextBox. I use "^?+(\.*)?$" to check for a real number. The control works fine as long as the user enters something in the TextBox; it does not...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
13
by: Wiseman | last post by:
I'm kind of disappointed with the re regular expressions module. In particular, the lack of support for recursion ( (?R) or (?n) ) is a major drawback to me. There are so many great things that can...
12
by: FAQEditor | last post by:
Anybody have any URL's to tutorials and/or references for Regular Expressions? The four I have so far are: http://docs.sun.com/source/816-6408-10/regexp.htm...
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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,...

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.