473,322 Members | 1,431 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.

regular expression for tags with there attribute and content.

Hi,

I'm new to regular expressions and having troubles recreating one that would
match tags with there attribute and content.

Example on which i'm doing the match:
[CODE class="testclass" created=John] protected void
btnLogout_Click(object sender, EventArgs e)<br / {<br />
this._db.SignOut(Session);<br / if (Session["User"] != null)<br />
Session.Remove("User");<br / FormsAuthentication.SignOut();<br />
Response.Redirect(Page.Request.Url.AbsoluteUri);<b r / }<br />[/code]

Most of the expression I got so far is working but the problem is when the
content between the tags contains a [ like in the example, my current regex
won't match that and I can't strip the tags to read the content since I can
have multiple tags in one line :/.

Expression so far:
(?<starttag>\[(?<tag>\w+)(?<attributes>[|:/\+\-\=\'\".?&amp;\w\s]*)\])(?<Content>[^\[]*)(?<endtag>\[\/\k<tag>\])

(?<starttag>\[(?<tag>\w+)(?<attributes>[|:/\+\-\=\'\".?&amp;\w\s]*)\]) <--
starttag (with attributes in) works, would match [CODE class="testclass"
created=John]

(?<attributes>[|:/\+\-\=\'\".?&amp;\w\s]*)\]) <-- attributes works, would
match class="testclass" created=John

(?<Content>[^\[]*) <-- content doesn't catch [

(?<endtag>\[\/\k<tag>\]) <-- endtag works, would match [/code]
Sep 9 '06 #1
1 1950
The following matches the content when used with the singleline option

\[(?<tag>\w+)(?<attributes>[|:/\+\-\=\'\".?&\w\s]*)\](?<content>.*?)\[\/\k<tag>\]

Jared

"Heron" wrote:
Hi,

I'm new to regular expressions and having troubles recreating one that would
match tags with there attribute and content.

Example on which i'm doing the match:
[CODE class="testclass" created=John] protected void
btnLogout_Click(object sender, EventArgs e)<br / {<br />
this._db.SignOut(Session);<br / if (Session["User"] != null)<br />
Session.Remove("User");<br / FormsAuthentication.SignOut();<br />
Response.Redirect(Page.Request.Url.AbsoluteUri);<b r / }<br />[/code]

Most of the expression I got so far is working but the problem is when the
content between the tags contains a [ like in the example, my current regex
won't match that and I can't strip the tags to read the content since I can
have multiple tags in one line :/.

Expression so far:
(?<starttag>\[(?<tag>\w+)(?<attributes>[|:/\+\-\=\'\".?&\w\s]*)\])(?<Content>[^\[]*)(?<endtag>\[\/\k<tag>\])

(?<starttag>\[(?<tag>\w+)(?<attributes>[|:/\+\-\=\'\".?&\w\s]*)\]) <--
starttag (with attributes in) works, would match [CODE class="testclass"
created=John]

(?<attributes>[|:/\+\-\=\'\".?&\w\s]*)\]) <-- attributes works, would
match class="testclass" created=John

(?<Content>[^\[]*) <-- content doesn't catch [

(?<endtag>\[\/\k<tag>\]) <-- endtag works, would match [/code]
Sep 9 '06 #2

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

Similar topics

2
by: Keith Morris | last post by:
Hi all! I'm creating a mini CMS that will store content in a MySQL database. What I am trying to do is parse the content and replace certain keywords with a link. The keywords and associated...
3
by: Ori | last post by:
Hi , I'm working with C#.NET and I'm looking for the following. I have a web page content and I want to pull all the text which appear in the page without all the HTML tags. I know that there...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
4
by: henrik | last post by:
Hi I have a regex question. I want to find all content of a <td class="someclass"> tag. This means the expression should include all other tags included between <td class="someclass"> and </td>....
3
by: orianavim | last post by:
Hi, i'm looking to find a way (using RegEx) to take the following text break it into 3 parts: <table><tr><td>#Content#</td></tr></table> which will give me an collection/list with 3 elements:...
12
by: stevebread | last post by:
Hi, I am having some difficulty trying to create a regular expression. Consider: <tag1 name="john"/ <br/<tag2 value="adj__tall__"/> <tag1 name="joe"/> <tag1 name="jack"/> <tag2...
1
by: Steve B. | last post by:
Hi, I'm building a web site that can render html from various user input. The problem is that the html cannot be trusted, so I need to ensure it does not contain script attack injection. That's...
1
by: Brad Everman | last post by:
Say I have an HTML file and want to convert all tags to lowercase, but leave the attributes alone. For instance: <SOME TAG ATTRIBUTE="Text THAT may be Upper"></SOME TAG> Needs to be converted...
2
by: Sami | last post by:
How can I get the inner content of a tag with regular expression I couldn't the the opening and closing tags to match properly Input "fjkdjfkdj <div>sadfdf dfdf...
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: 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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.