473,396 Members | 2,011 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,396 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 21 '05 #1
5 1058
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 21 '05 #2
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 21 '05 #3
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 21 '05 #4
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 21 '05 #5
"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 21 '05 #6

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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...
0
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...
0
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,...

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.