473,322 Members | 1,699 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,322 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 1056
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.