473,804 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="testclas s" created=John] protected void
btnLogout_Click (object sender, EventArgs e)<br / {<br />
this._db.SignOu t(Session);<br / if (Session["User"] != null)<br />
Session.Remove( "User");<br / FormsAuthentica tion.SignOut(); <br />
Response.Redire ct(Page.Request .Url.AbsoluteUr i);<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+)(?<a ttributes>[|:/\+\-\=\'\".?&amp;\w \s]*)\])(?<Content>[^\[]*)(?<endtag>\[\/\k<tag>\])

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

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

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

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

\[(?<tag>\w+)(?<a ttributes>[|:/\+\-\=\'\".?&\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="testclas s" created=John] protected void
btnLogout_Click (object sender, EventArgs e)<br / {<br />
this._db.SignOu t(Session);<br / if (Session["User"] != null)<br />
Session.Remove( "User");<br / FormsAuthentica tion.SignOut(); <br />
Response.Redire ct(Page.Request .Url.AbsoluteUr i);<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+)(?<a ttributes>[|:/\+\-\=\'\".?&\w\s]*)\])(?<Content>[^\[]*)(?<endtag>\[\/\k<tag>\])

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

(?<attributes>[|:/\+\-\=\'\".?&\w\s]*)\]) <-- attributes works, would
match class="testclas s" 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
2623
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 links are kept in a MySQL table. Here is an example. $keyword = "Widgets Technology Co."; $location = "http://www.widgets.com/about";
3
1556
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 is a way to do it with regular expression. Does someone know how to do it ? Please help….
4
3235
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 over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no specific format and I have to detect and remove them using a list of strings that may appear as...
4
3150
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>. Please help Regards
3
300
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: <table><tr><td> #Content#
12
337
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 value="adj__short__"/> Whenever a tag1 is followed by a tag 2, I want to retrieve the values
1
2038
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 why I'd like to provide a set of allowed tag and to remove other ones. I think about regular expression. However, I was able to find some regex samples that remove a set a untrusted tags (scripts, iframe, etc), but I'd
1
1302
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 to: <some tag attribute="Text THAT may be Upper"></some tag> I can easily convert everything in the tag to lower using '<.*?>' but am
2
4801
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 <b>dfd</b>dfdf<div>nested<div>tags</div>.</div> </div>dfdfdf" Get content of the first div tag
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.