C# - Forum Tags: Can Regex Be Modified To Grab Nested Tags?

Feb 24, 2011

I am building a forum and I want to use forum-style tags to let the users format their posts in a limited fashion.Currently I am using Regex to do this.As per this question:How to use C# regular expressions to emulate forum tags. The problem with this,is that the regex does not distinguish between nested tags.Here is a sample of how I implemented this method:

public static string MyExtensionMethod(this string text){return TransformTags(text);}
private static string TransformTags(string input)
{string regex = @"[([^=]+)[=x22']*(S*?)['x22]*](.+?)[/(1)]";
MatchCollection matches = new Regex(regex).Matches(input);
for (int i = 0; i < matches.Count; i++)
var tag = matches[i].Groups[1].Value;
var optionalValue = matches[i].Groups[2].Value;
var content = matches[i].Groups[3].Value;
Now,if I submit something like [quote] This user posted [quote] blah [/quote] [/quote] it does not properly detect the nested quote.Instead it takes the first opening quote tag and puts it with the first closing quote tag.Do you guys recommend any solutions?Can the regex be modified to grab nested tags?Maybe I shouldn't use regex for this?

View 3 Replies


Similar Messages:

Remove All Html Tags And Javascript Tags Using Regex In Javascript

Jan 31, 2011

How can I remove all html tags and script tags? consider also short tags like unclosed tags

<script>blah...</script>
<body> aaa<b>bbb</body>

This should return aaa bbb.

notice that all the contents inside the script tag is ignored.

View 3 Replies

Use C# Regular Expressions To Emulate Forum Tags?

Feb 5, 2011

I am building a forum and I want to be able to use simple square bracket tags to allow users to format text. I am currently accomplishing this by parsing the string and looking for the tags. It's very tedious, especially when I run into a tag like this [URL]. Having to parse the attribute, and the value, and make sure it has proper opening and closing tags is kind of a pain and seems silly. I know how powerful regular expressions are but I'm not good at them and they frustrate me to no end. I think an example would get me started. Just a regex for finding tags like [b]bolded text[/b] and tags with attributes like the link

View 2 Replies

.net Regex To Find Anchor Tags And Replace Their Url?

May 13, 2010

i'm trying to find all the anchor tags and appending the href value with a variable.
for example

<a href="/page.aspx">link</a> will become <a href="/page.aspx?id=2">
<A hRef='http://www.google.com'><img src='pic.jpg'></a> will become <A hRef='http://www.google.com?id=2'><img src='pic.jpg'></a>

I'm able to match all the anchor tags and href values using regex, then i manually replace the values using string.replace, however i dont think its the efficient way to do this.Is there a solution where i can use something like regex.replace(html,newurlvalue)

View 3 Replies

AJAX :: Script Tags Rendered Inside The Body Tags?

Jun 26, 2010

i have created a aspx page with the script manager, update panels and so on. Now, when i use some jquery functions which are included inside the head tags, when the page is run, i find the script tags generated inside the body instead of the head tag. i'm using visual studio 2005 only.

View 2 Replies

How To Apply CSS Tags To <li> Tags When Using 4.0 Menu Control

Feb 1, 2011

Is there a way to apply your own CSS tags to <li> tags when using ASP .NET 4.0 menu control? For example, say I have an external style sheet that has tags "class1", "class2", "class3", and etc. I want to apply "class1" to the first menu item. Then if menu item is selected, I want to apply "class2" and if it's not selected, "class3". I played with various 'Static' styles, but just can't get it work. I finally gave up and created my own menu control that extends ASP .NET menu control and provides my own custom rendering. This works, but I'm wondering if there is a way to get it work with built-in menu control.

View 1 Replies

Remove Style Tags,css,scripts And Html Tags From Html To Plain Text?

Mar 8, 2011

I want regex operation for removing style tags,css,scripts and html tags from html to plain text in asp.net c#...

View 1 Replies

AJAX :: Getting Html Tags Output Instead Of Executed Html Tags

Mar 27, 2010

i'm doing ajax website using PostWebRequest() function, when i call any .aspx page to the target html element the output is coming fine in IE but in FF(FireFox) is coming in html format(html tags) IE output : [URL] FF output : [URL]

javascript functions :
function PostWebRequest(postPage, HTMLTarget, parameter) {
displayElement = $get(HTMLTarget);
displayElement.innerHTML = "<div style='text-align:center;'><br /><br /><br /><br /><br /><img src='images/ajax-loader.gif' algin='center' /></div>";
var wRequest = new Sys.Net.WebRequest();
wRequest.set_url(postPage);
wRequest.set_httpVerb("POST");
var body = parameter;
wRequest.set_body(body);
wRequest.get_headers()["Content-Length"] = body.length;
wRequest.add_completed(onWebRequestCompleted);
wRequest.invoke();
}
function onWebRequestCompleted(executor, eventArgs) {
if (executor.get_responseAvailable()) {
if (document.all) {
displayElement.innerHTML = executor.get_responseData();
}
else {
displayElement.textContent = executor.get_responseData();
}
}
else {
if (executor.get_timeOut()) {
alert("Timed Out");
}
else {
if (executor.get_aborted())
alert("Aborted");
}
}
}

View 1 Replies

Forms Data Controls :: Nested Gridview To Show Category And Forum?

Aug 30, 2010

there is category and under its there are all forum of this category

to do that , I create 2 tables in DB

cat for category have 2 rows ( id,title) and table forum have 3 rows ( id,title,Cat_ID)

I can do it with Php but in asp.net I can't

I read in some article to create nested gridview

View 4 Replies

Web Parts - Contain Tags?

Feb 16, 2011

My aspx page contains a region which is populated trough ajax. The pupulated content is that of the page MyWebpart.aspx. But MyWebpart.aspx contains not only a grid(which is what I need to get trough ajax), it also contains , , , tags because this are required for any aspx file.code to replace inner html with that received from webpart

displayElement.innerHTML += executor.get_responseData();

View 1 Replies

Firefox Won't Display All Tags?

Mar 5, 2011

I have an issue with Firefox. After creating a new template for my website using <div> tags, i noticed that not all tags are displayed when i preview the site in firefox.

I put the sample template in the following location:

[URL]

I was able to verify my CSS with the following link: [URL] and it passed without any problems. The html part is correct as well.

My question is how come two div tags: <div class="header9"></div> and <div id="sidebar"></div> are not displayed in firefox. It works fine with explorer but firefox has issues.

Also the background-color for <body> takes over in the middle, even though i've created a <div id="wrapper"> with all divs inside and background color assigned to white.

I've tried developer extension for firefox but still was not able to find the problem.

It's very annoying that simple (basic) tags such <div> could have isssues being displayed. Does anyone know what am i doing wrong and how to fix that issue?

View 7 Replies

How To Use Basic Html Tags

Jun 27, 2010

how can i use basic html tags(h1,h2 and <p>) in code behind.

View 4 Replies

Dynamic Meta Tags Using SQL And VB?

Jul 27, 2010

I am new to ASP.NET and I am trying to dynamically bind the Meta Keywords, Title and Description from a SQL database to a MasterPage / Code Behind file using VB. I need to know what goes into the Master Page and what goes in the Code Behind file. My database is named "Products" and the columns I need to bind are Keywords, WebTitle, and Description.

View 2 Replies

How To Get Rid Of HTML-tags In A Message

Mar 8, 2011

For the last time I've been using EWS MAPI to connect to Exchange Server. After this is done I access my mails and firstly display their body (which contains a LOT HTML-tags) in a gridview. After you select a record of that gridview the body is shown in a freetextbox.

View 3 Replies

SQL Server :: Get The Last 3 Tags That Added To The Db

Oct 11, 2010

I want get the last 3 tags that added to the db. My Tag table schema is:

TBL TAG:
CREATE TABLE [dbo].[tblTag](
[TagId] [int] IDENTITY(1,1) NOT NULL,
[Header] [nvarchar](200) NULL,
[IsActive] [tinyint] NULL DEFAULT ((0)),
[Ordered] [int] NOT NULL DEFAULT ((1)),
[Language] [nvarchar](5) NULL,
[DateTime] [smalldatetime] NULL,
[Official] [nvarchar](max) NULL,
[LastUpdate] [datetime] NULL,
[Locked] [tinyint] NULL,
[LastUpdateUser] [nvarchar](256) NULL,
[NumViews] [bigint] NULL,
[AllUserModified] [nvarchar](max) NULL,
CONSTRAINT [PK_tblTag] PRIMARY KEY CLUSTERED
(
[TagId] ASC
)

My TagtoMoudule table:

CREATE TABLE [dbo].[tbl_Module_Tag](
[AutoId] [int] IDENTITY(1,1) NOT NULL,
[ModuleId] [int] NOT NULL,
[ItemId] [int] NOT NULL,
[TagId] [int] NOT NULL
) ON [PRIMARY]

I want get the last 3 items in the tbl_Module_Tag but with no duplicate value, get uniq tags For exemple If the data the query "select tagid from tbl_Module_Tag order by autoid desc" return this values..........

View 5 Replies

How To Use ID Tags On Server Controls

Apr 28, 2010

Some of my servercontrols dont need ID's (i never need to access them from codebehind), removing them is rendering fine without comlaints. Is this ok?

why im dont want IDs? im using a .resx for different languages and from what I understand these must tied to a server control. And im tired of comming up with new pointless unique names. Also the these ID's gets insanly long as clientID.

View 1 Replies

Server Tags Cannot Contain Constructs?

Feb 24, 2011

I have a (image button)

<asp:ImageButton
ID="ImageButton1"
runat="server"
ImageUrl="../Images/checkout/Proceed_To_Checkout_Button.png"
onclick="top.location='<%=string.Format("MyAccount.aspx?action=new&returnUrl={0}",
Web.ProcessFlow.Common.QueryString(Request.QueryString["returnUrl"]))%>'"
/>

I get this error when I push the button:

Server tags cannot contain <% ... %> constructs.

I have tried <# too
it didn't help.

View 1 Replies

C# - Server Tags In Markup?

Feb 4, 2011

Morning all I have frequently used the old

<asp:Label ID="lblWas" runat="server" Text='<%# XPath("FACEVALUE") %>'></asp:Label>

This type of thing. when I first came across it I loved it, i'm using it again today but not quite so simply. I have a number of extra things I would like to achieve.

Apply formatting to the value. Like Text='<%# string.Format(XPath("FACEVALUE"), "{0:c}") %>'>
<asp:LinkButton ID="lnkBook" runat="server" PostBackUrl='/THEATRE/' + XPath("FACEVALUE")>Book</asp:LinkButton>

For option number 2 the URL is not as I would expect, and for number 1 I cannot get the syntax correct if it's even possible.

I have not been able to find something suitable in google. Hopefully what I am trying to achieve is obvious from the example :)

View 3 Replies

Get Html Tags From Textbox In C#

Sep 2, 2010

I have a text area in my ASP.NET web application that is used to enter html code. Now there is also an button control, which upon clicking should retrieve just the text placed between certain html tags in the text box. For example:

1) User types html code including tags etc. and clicks the OK button
2) In my code the text from the text area is retrieved and only the part between a <p></p> tag should be saved to a string object.

I can obviously get the text from the text area and attach it to a string object but I am not able to work out how to just get text within a certain html tag like <p></p>

View 2 Replies

How To Get A Text Enclosed By Two Tags

Oct 14, 2010

I am working with ASP.NET and need to manage with a string typed by the user in order to extract some information. The user enters a normal text, words and numbers, but sometimes he may type a mathematical expression in MATHML, these expressions are always an xml string enclosed by the tag. I want to extract from the typed text every math segment. For example, let's consider the user typed this text:

string input = "My name is Dorry and here is a math expression: <math>---some math1---</math> ah, there is another expression: <math>---some math2---</math> and do not forget this too <math>---some math3---</math>.".

Well, The first regex solution I came up with is this:

string pattern1 = @"<math(.+)</math>";

To get matches I obviousely use:

Regex r = new Regex(pattern1, RegexOptions.IgnoreCase);
string[] res = r.Matches(input);

And it seemd working, too bad, it does not because this expression, instead of getting me an array (using Reges.Matches) filled with three strings ("---some math1---", "---some math2---", "---some math3---"); it gets me an array with one element only: "---some math1--- ah, there is another expression: ---some math2--- and do not forget this too ---some math3---". Can you see? it takes the first and the last and merges everything in the middle WITHOUT CARING of some other or elements in the way!

Well, I suppose this is a well known issue about regular expressions; is there a solution? how to tell the regex engine to be a little more... aware?

View 5 Replies

Unclosed Tags In A String

Oct 10, 2010

In my string I have some unclosed html tags. For example

<div><p></p>
<p><b></p>

View 1 Replies

C# - Can Get Values From HTML Tags

Feb 12, 2010

I want to get some data from html tags in a web page. For example I have a web site that's got [URL], this is text which I want to split. I want to first URL, First text thats between in first span tags and last text that's between the last span tags.

How can I do this with C# ASP.NET 2.0 (not 3.5)?

<a class="tablolinkmetin" target="_blank" href="http://www.iwantthisurl.com/test/2010/subat/12022010_adli_krrnme.htm">
<img alt=icon src="images/icon/ok.gif" border=0 width="7" height="8">
<span class=tablolink>
<span class="genelgeler_mbaslik">I want this text.</span>
</span>
<span class="tablolinkaltyazi"><br>and i want here</span>
</a>
<img src="images/icon/cizgi.png" width="260" height="1"><br>

View 2 Replies

Way In Javascript To Remove Tags

Mar 14, 2011

if there is there away in javascript to remove any tags that are <h1 /> <h2 /> <h3 /> <h4 /> etc from the HTML editor?i use javascript function below to insert my custom styles from outside the editor, so at the end i need a way to searh all the content and remove the unwanted tags that are created by the editor?

[Code]....

View 3 Replies

C# - Network Tags In Web.config?

Jul 19, 2010

i hae a doubt in my web application i place two network tags in smtp like this...

<system.net>
<mailSettings>
<smtp>
<network host="webmail.xxx.com" port="25" userName="info@xxx.com" password="asdf" defaultCredentials="false"/>
<network host="webmail.yyy.com" port="25" userName="info@yy.com" password="asdf12" defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>

View 1 Replies

Two Elements On One Line Using Div Tags?

Mar 14, 2011

Eventually, our team would like to move away from tables, but it seems like div tags are so much harder to use. In the above image, the layout was created using a table, but I cant figure out how to get a basic column structure working using div tags. How can I get those buttons on the same line? HTML newbie here.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved