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?
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
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)
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.
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.
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"); } } }
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
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?
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.
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.
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..........
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.
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 :)
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>
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?
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.
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?
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.