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

some help with regex

hi,

I'm trying to write my own code-dom because I don't like the ms one ;-)

I want to look for this expression, ( using someword; ) but I can only
figure out basic things like searching for words that start a-zA-Z etc based
on my regex books and online documentation.

I will also need to look for things like;

public class somename (....); this kind of line might be on two lines ....
so I guess its some expression like

anyword CLASS anyname (some params);

can anyone help?

thanks
-c

(you can msg me via www.typemismatch.com)
Nov 16 '05 #1
4 1203
"ilPostino" <ne**@ip80.com> wrote in
news:%2****************@tk2msftngp13.phx.gbl...
hi,

I'm trying to write my own code-dom because I don't like the ms one ;-)

I want to look for this expression, ( using someword; ) but I can only
figure out basic things like searching for words that start a-zA-Z etc
based on my regex books and online documentation.

I will also need to look for things like;

public class somename (....); this kind of line might be on two lines ....
so I guess its some expression like

anyword CLASS anyname (some params);

can anyone help?


"\b(public\s*|private\s*|internal\s*|)class\s+(\w) +\b([^{])*{" worked in
expresso;

Just to make sure: You do know that you won't be able to parse C# using
regular expressons? It's a recursive language, MS regex's can do a little
nested-paren matching, but for C# you will almost definitely need a
full-blown parser.

Niki
Nov 16 '05 #2
thanks, can you recommend any parsers then?

I just need to parse out down to the Method level inside a class or the code
inside an event etc, I never need to actually
parse the code itself, just definitions.

That regex makes sense, thanks.

-c

"Niki Estner" <ni*********@cube.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"ilPostino" <ne**@ip80.com> wrote in
news:%2****************@tk2msftngp13.phx.gbl...
hi,

I'm trying to write my own code-dom because I don't like the ms one ;-)

I want to look for this expression, ( using someword; ) but I can only
figure out basic things like searching for words that start a-zA-Z etc
based on my regex books and online documentation.

I will also need to look for things like;

public class somename (....); this kind of line might be on two lines
.... so I guess its some expression like

anyword CLASS anyname (some params);

can anyone help?


"\b(public\s*|private\s*|internal\s*|)class\s+(\w) +\b([^{])*{" worked in
expresso;

Just to make sure: You do know that you won't be able to parse C# using
regular expressons? It's a recursive language, MS regex's can do a little
nested-paren matching, but for C# you will almost definitely need a
full-blown parser.

Niki

Nov 16 '05 #3
I thought maybe ms's codecom could parse it but they didn't provide a parser
.... :(

-c

"Niki Estner" <ni*********@cube.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"ilPostino" <ne**@ip80.com> wrote in
news:%2****************@tk2msftngp13.phx.gbl...
hi,

I'm trying to write my own code-dom because I don't like the ms one ;-)

I want to look for this expression, ( using someword; ) but I can only
figure out basic things like searching for words that start a-zA-Z etc
based on my regex books and online documentation.

I will also need to look for things like;

public class somename (....); this kind of line might be on two lines
.... so I guess its some expression like

anyword CLASS anyname (some params);

can anyone help?


"\b(public\s*|private\s*|internal\s*|)class\s+(\w) +\b([^{])*{" worked in
expresso;

Just to make sure: You do know that you won't be able to parse C# using
regular expressons? It's a recursive language, MS regex's can do a little
nested-paren matching, but for C# you will almost definitely need a
full-blown parser.

Niki

Nov 16 '05 #4
"ilPostino" <ne**@ip80.com> wrote in
news:%2****************@TK2MSFTNGP14.phx.gbl...
thanks, can you recommend any parsers then?

I just need to parse out down to the Method level inside a class or the
code inside an event etc, I never need to actually
parse the code itself, just definitions.

That regex makes sense, thanks.


The problem is that classes/namespaces/structs can be nested: a class can
contain another class, which can contain another class, to any level.
Regex's aren't good tools for that kind of input. If you only want to get a
"flat" layout of a file, without nesting information, and if you're not
interested whether the file is syntactically correct, then regex's are
probably fine, otherwise you'll have to build a parser.

I must admit I never did that in C#, but Yacc or Antlr used to be good tools
in C++-times, maybe you can find C# versions of these.

Niki
Nov 16 '05 #5

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

Similar topics

8
by: Beznas | last post by:
Hi All; I'm trying to create an ASP function called CleanX that removes the punctuation and some characters like (*&^%$#@!<>?"}|{..) from a text string I came up with this but It...
3
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
2
by: Daniel Billingsley | last post by:
First, if MSFT is listening I'll say IMO the MSDN material is sorely lacking in this area... it's just a whole bunch of information thrown at you and you're left to yourself as to organizing it in...
5
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
4
by: Flomo Togba Kwele | last post by:
I am having difficulty writing a Regex constructor. A line has a quote(") at its beginning and its end. I need to strip both characters off. If the line looks like "1", I need the result to be 1....
3
by: R. K. Wijayaratne | last post by:
Hello everyone, I have something similar to the below and I am trying to select just the Block 1 markup/text <li><ul>...</ul></liwith the following RegEx @"<li>(.|\n)*<ul>(.|\n)*</ul>\n*</li>",...
0
by: Karch | last post by:
I have these two methods that are chewing up a ton of CPU time in my application. Does anyone have any suggestions on how to optimize them or rewrite them without Regex? The most time-consuming...
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
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...

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.