regular expression for tags with there attribute and content.

H

Heron

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);<br /> }<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]
 
G

Guest

The following matches the content when used with the singleline option

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

Jared
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top