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>[|:/\+\-\=\'\".?&\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]
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>[|:/\+\-\=\'\".?&\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]