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

Using a regular expression to parse comments from aspx (ASP.NET) files

I need a simple way to parse comment lines from aspx (ASP.NET) files;
in which comments are surounded by

<%!-- and --%>

So I created a simple regex:

<%!--(?<val>.*)--%>

With 'singleline' option on, and the following as input...

<%!-- single line comment --%>
<table>table contents here</Table>
<%!-- multiline
wrapped
comment
--%>

.... and the entire input was the match.

I've also tried:
<%!--(?<val>[^(--%>)]*)--%>

But this excludes any comment that has a dash, percent, OR greater
than sign as part of the comment text.

I've also tried lookbehind assertions with no success. But maybe I'm
doing it wrong?

<%!--(?<val>.*(?<!--%>))--%>

If anyone has an idea what I am doing wrong, please let me know.

Thanks,
Michael Lang
Nov 16 '05 #1
4 1739
Have you tried "^<%!--(?<val>.*)--%>$" ?
^ means beginning of line and $ means end of line
"Michael Lang" <ve********@icqmail.com> wrote in message
news:da**************************@posting.google.c om...
I need a simple way to parse comment lines from aspx (ASP.NET) files;
in which comments are surounded by

<%!-- and --%>

So I created a simple regex:

<%!--(?<val>.*)--%>

With 'singleline' option on, and the following as input...

<%!-- single line comment --%>
<table>table contents here</Table>
<%!-- multiline
wrapped
comment
--%>

... and the entire input was the match.

I've also tried:
<%!--(?<val>[^(--%>)]*)--%>

But this excludes any comment that has a dash, percent, OR greater
than sign as part of the comment text.

I've also tried lookbehind assertions with no success. But maybe I'm
doing it wrong?

<%!--(?<val>.*(?<!--%>))--%>

If anyone has an idea what I am doing wrong, please let me know.

Thanks,
Michael Lang


Nov 16 '05 #2
No. I want comments that also happen to span more than one line. I
also want to FIND the match in a larger string context, not just see
if a single line is a comment.

"Magne Ryholt" <ma**********@bluezone.no> wrote in message news:<uE**************@TK2MSFTNGP15.phx.gbl>...
Have you tried "^<%!--(?<val>.*)--%>$" ?
^ means beginning of line and $ means end of line
"Michael Lang" <ve********@icqmail.com> wrote in message
news:da**************************@posting.google.c om...
I need a simple way to parse comment lines from aspx (ASP.NET) files;
in which comments are surounded by

<%!-- and --%>

So I created a simple regex:

<%!--(?<val>.*)--%>

With 'singleline' option on, and the following as input...

<%!-- single line comment --%>
<table>table contents here</Table>
<%!-- multiline
wrapped
comment
--%>

... and the entire input was the match.

I've also tried:
<%!--(?<val>[^(--%>)]*)--%>

But this excludes any comment that has a dash, percent, OR greater
than sign as part of the comment text.

I've also tried lookbehind assertions with no success. But maybe I'm
doing it wrong?

<%!--(?<val>.*(?<!--%>))--%>

If anyone has an idea what I am doing wrong, please let me know.

Thanks,
Michael Lang

Nov 16 '05 #3
Michael Lang wrote:
I need a simple way to parse comment lines from aspx (ASP.NET) files;
in which comments are surounded by

<%!-- and --%>

So I created a simple regex:

<%!--(?<val>.*)--%>

With 'singleline' option on, and the following as input...

<%!-- single line comment --%>
<table>table contents here</Table>
<%!-- multiline
wrapped
comment
--%>

... and the entire input was the match.


Use the non-greedy quantifier and treat the input as one string. The
"Singleline" option allows the "." to match the newline character. (The
following example also does not capture the leading and trailing spaces.)

Regex regex = new Regex(@"
<%!--\s*(?<val>.*?)\s*--%>",
RegexOptions.IgnoreCase |
RegexOptions.Singleline);

--
Take care,
Ken
(to reply directly, remove the cool car. <sigh>)
Nov 16 '05 #4
Thanks!!! That is exactly what I was looking for. I've tested it
with various input files and it works as expected.

Ken Arway <ka****@jaguar.att.net> wrote in message news:<ew**************@TK2MSFTNGP10.phx.gbl>...
Michael Lang wrote:
I need a simple way to parse comment lines from aspx (ASP.NET) files;
in which comments are surounded by

<%!-- and --%>

So I created a simple regex:

<%!--(?<val>.*)--%>

With 'singleline' option on, and the following as input...

<%!-- single line comment --%>
<table>table contents here</Table>
<%!-- multiline
wrapped
comment
--%>

... and the entire input was the match.


Use the non-greedy quantifier and treat the input as one string. The
"Singleline" option allows the "." to match the newline character. (The
following example also does not capture the leading and trailing spaces.)

Regex regex = new Regex(@"
<%!--\s*(?<val>.*?)\s*--%>",
RegexOptions.IgnoreCase |
RegexOptions.Singleline);

Nov 16 '05 #5

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

Similar topics

43
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the...
4
by: Aah | last post by:
Where can I get a good resource to know more about Regular expression in vb.net I have like 1000 asp/aspx files where I need to find certain file path and update it with certain text. I am...
23
by: Charles Law | last post by:
Does anyone have a regex pattern to parse HTML from a stream? I have a well structured file, where each line is of the form <sometag someattribute='attr'>text</sometag> for example <SPAN...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
3
by: Robert Scheer | last post by:
Hi. I have a regularexpression validator control on a page. This regular expression validates a textbox to accept only numbers and commas: validationexpression="*" I am trying to modify this...
5
by: Avi Kak | last post by:
Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex =...
6
by: =?Utf-8?B?U2FtZWVrc2hh?= | last post by:
Hi, I want to write a simple .net program to open a URL, fill in fields, and click on a button to submit it using .net 1.1 framework. Can someone help in suggesting the libraries I should use?...
14
by: Nick Maclaren | last post by:
For reasons that I won't explain, as they are too complicated and not terribly relevant, I am interested in discovering what people actually use regular expressions for. Not the subject domain,...
0
by: ahropak | last post by:
Hi, I have a question regarding a regular expression within Regex.Split() method which will help me to break each line of code into tokens. I'm trying to parse some lines of C# source code and...
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...
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: 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
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...

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.