RegExp for replacing specific HTML tags.

Hi All,
I need to replace some of the HTML tags in flex.
for eg:-
in the follwing html i have to replace "span","div" and "a"
<h2>AAAAAAAAA<br /><span >BBBBBBBBBBB</span></h2><div><p>QQQQQQ</p><p>EE<br />FFFF<br />TTT<br /></p
<a href="#">Click</a>
</div>

input = "yor html string";
var urlPattern:RegExp = new RegExp("/(<a)(.*)(</a)/","ig");
var result:String = input.replace(urlPattern, "<b$2</b"); 
var urlPattern2:RegExp = new RegExp("/(<div)(.*)(</div)/","ig");
var result2:String = result.replace(urlPattern2, "<table$2</table"); 
and so on....
hope this helps ...

Similar Messages

  • Converter for converting all HTML tags to JSF tags

    hai all,
    i am new to JSF. i need a suggestions to convert all my HTML pages to JSF pages bcoz i was already created more pages in HTML and now i want to convert all the pages to JSF. can u give any suggestion plz post it here or send me a mail to [email protected]
    thanks in advance,
    regards,
    V.Sabarish

    hi roman,
    thanks for ur reply. it converts the file but the links r not converting....so can u suggest me another way for converting a HTML tags to JSF tags.

  • How to use Microsoft Word's Find and Replace with HTML tags?

    Hello to all!
    I'm trying to figure out how to use the find and replace function in Word to replace html tags. I'd like to be able to change something like this:
    <span class="B01-K-ITAL">random text</span>
    To something like this:
    <em>random text</em>
    I want to replace the open and close tags without changing or interfering with the text between the tags. I'm pretty sure I should use wildcards, but I can't figure out how to use them properly.
    Anyone able to lend a hand?

    Here is my latest regular expression with Perl.   I think it matches the spirit of the request in the original post.
    Note, this isn't as easy as you think.  You need to code up the complete set of html rules in you implementation. You need to allow for a certain amount of mal-formed html.
    perl -0660pe 's^<[sS][pP][aA][nN]\s+class="B01-K-ITAL"\s*>(.*?)</[sS][pP][aA][nN]>^<em>$1</em>^gs' i.html >|o.html
    input text
     <html> <head>...</head> <body>I'd like to be able to change something like this: <span class="B01-K-ITAL">#1 one line</span> I want to replace the open and close tags without changing or interfering with the text between the tags. I'm pretty sure I should use wildcards, but I can't figure out how to use them properly. <p>note, this isn't as easy as you think.  You need to code up the complete set of html rules in you implementation. You need to allow for a certain amount of mal-formed html.</p> <span class="B01-K-ITAL">#2 don't be greedy</span> <span class="B01-K-ITAL">$3 multiline text</span> <span class="B01-K-ITAL">#4 multiline tag. I believe html allow a carriage return in white space of tags</span> <span class="B01-K-ITAL">#5 split after the class tag. optional white space</span> <sPan class="B01-K-ITAL">#6 mixed case tag</Span> <p>no text #7</p><span class="B01-K-ITAL"></span> <!-- Apparently, this is valid     http://www.positioniseverything.net/articles/cc-plus.html --> <!--[if IE]> <div id="IEroot"> <![endif]--> <p id="IE">This browser is IE.</p> <p id="notIE">This browser is not IE.</p><!--[if IE]> </div> <![endif]--></body> </html>
    output text
     <html> <head>...</head> <body>I'd like to be able to change something like this: <em>#1 one line</em> I want to replace the open and close tags without changing or interfering with the text between the tags. I'm pretty sure I should use wildcards, but I can't figure out how to use them properly. <p>note, this isn't as easy as you think.  You need to code up the complete set of html rules in you implementation. You need to allow for a certain amount of mal-formed html.</p> <em>#2 don't be greedy</em> <em>$3 multiline text</em> <em>#4 multiline tag. I believe html allow a carriage return in white space of tags</em> <em>#5 split after the class tag. optional white space</em> <em>#6 mixed case tag</em> <p>no text #7</p><em></em> <!-- Apparently, this is valid     http://www.positioniseverything.net/articles/cc-plus.html --> <!--[if IE]> <div id="IEroot"> <![endif]--> <p id="IE">This browser is IE.</p> <p id="notIE">This browser is not IE.</p><!--[if IE]> </div> <![endif]--></body> </html>

  • Need to copy Data from a specific Html Tag

    Hello,
    I am trying to use CF to access website and capture data from a specific tag to the end of that tag and store same in a csv file or database.
    The tag based search of an open file is where I am not able to get any head way. Any one has done this?

    You'll need to use a regular expression for that. CF supports regular expressions with the REFind, REFindNoCase and REReplace functions. Here's an example of using regular expressions to capture the value within an HTML tag:
    http://www.javamex.com/tutorials/regular_expressions/example_scraping_html.shtml
    It's in Java, but the syntax for regular expressions is the same in CF.
    Dave Watts, CTO, Fig Leaf Software
    http://www.figleaf.com/
    http://training.figleaf.com/
    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
    GSA Schedule, and provides the highest caliber vendor-authorized
    instruction at our training centers, online, or onsite.
    Read this before you post:
    http://forums.adobe.com/thread/607238

  • Regex - Remove specific HTML Tags

    I have already found a solution in the forum to remove all html tags but I need some specific tags - img, a, b, i, u - and also their closing tags - </a>, </b>.
    The regex also needs to differ between img without the class attribute and with class attribute - it should remove elements with class attribute
    So I have tried to modifiy the found solution:
    result = Regex.Replace(result, "<[^(img|a|b|i|u)][^>]*>", " ");
    It works not optimal because it also removes the closing tags, doesn't differ and doesn't remove the br tags. It's not necessary to do all these actions in one statement.

    you can use regular
    <[(/body|html)\s]*>
    in c#:
    var result = Regex.Replace(html, @"<[(/body|html)\s]*>", "");
    <html>
    <body>
    < / html>
    < / body>

  • Search for strings inside html tags ?

    Is there any way to get Spotlight to find search strings inside html documents? One example is I want to find any file that includes a certain alt=" " string inside an img src tag.
    Spotlight does not seem to include anything inside html tags in it's search, as far as I can tell.
    Am I missing something? Is there something I need to do?
    Thanks for any ideas,
    KarenD
    G5   Mac OS X (10.4.4)  
    G5   Mac OS X (10.3.5)  

    Very strange--it does find text inside the html files, but indeed does not seem to have text that is in the file but only appears within a tag. The solution is EasyFind by Christian Grunenberg:
    http://www.grunenberg.com
    You can do a content search on files in a particular folder, which I recommend since it does a brute force search and can take awhile if it has to search everything.
    Francine
    Schwieder

  • Help needed in writing custom views for rendering new HTML tags

    Hi
    I am in the process of making a sort of HTML editor using the JEditorKit and all,now i need to write a view which will display bi-directional text(text in reverse order),well i am not being able to get to the test at all,i don't know how to get to the text in the element being supplied to my ViewFactory.
    Anyone who knows anything about what i am talking here please help me,i am open to any suggestion,anything,i am in a real mess here,please help

    Hi,
    You dont need any coding to set the changed value back to the context attribute.
    Since you have mapped the context attribute in the DisplayView and EditView to a context attribute of component controller. So after viewing the name in your DisplayView when you navigate to EditView onActionChange,you can change the value.When you cahnge the value and submit the new value that is entered is update across the component controller and DisplayView context.
    To see this create a action onActionSubmit in EditView and navigate to the DisplayView, you will see the updated value.
    In webdynpro framework when the value of a context attribute is changed, then the value gets updated across all views to which the context attribute is mapped.

  • Replace HTML tags in RTE

    Hi All,
                   I've requirement that I need to replace the html tags in RTE, I checked find and replace plugin, which only replace the text not the tags. The CQ.form.rte.SearchableDocument returns the plain text. Can anybody tell me how to replace the tags?, is there any existing plugin's available ?
    Thanks in advance
        Ganesh

    Hi Ganesh,
        You can configure the rich text editor to use semantic markup, so that the bold=strong and italic=em will be modified in the html out. Not sure it applies for other tags. Give a try.
    http://forums.adobe.com/message/4652639#4652639
    Thanks,
    Sham

  • HTML Tags not moved in PDF

    Hello,
    I would like to print a report as a PDF and use the BI Publisher.
    This functions so far also quite well, only I have the problem
    I pass a HTML formatted text from a field CLob
    and with the PDF output the HTML tags are not moved.
    In the PDF document the HTML tags stands instead of a formatted heading,
    e.g.
    <*h1> This is the heading <*/h1> (without stars)
    What I must set / make with it I also a formatted one
    Heading agrees?
    Somebody an idea?
    Edited by: user10460383 on 14.09.2009 06:16
    Edited by: user10460383 on 14.09.2009 06:17

    True - a PDF isn't going to support HTML encoding. HTML will just be seen as more text, and displayed that way.
    You can strip out HTML tags fairly easily with a regular expression in your query SQL - this simply looks for text between < and > characters, and removes it. That should work for basic HTML formatting tags, but it isn't 100% (it won't handle <script> blocks correctly, for instance).
       select regexp_replace(myHTML, '<[^>]*>', '') as myText
       from myTable... Implementing a method to convert the HTML formatting into RTF formatting is also possible, but not a trivial task - you'd effectively have to replace each HTML tag with an RTF equivalent -- eg, replace <H1> with the RTF code to make a larger font, replace </H1> with RTF code to return the font to normal... etc...

  • Suppressing certain HTML tags before setting text to JEditorPane

    Sir,
    I am setting the text(html format) for JEditorPane using the setText(String) method. But I need to suppress all the <IMG> tags that are present in this text before setting it to JEditorPane. Is there any way in which I can write my extended HTMLEditorKit wherein I can check for specific HTML.Tag and prevent it from getting added to the document.
    Can you please help me out with some example.
    Regards,
    Alex

    Instead of trying to extend the HTMLEditorKit, you don't you add a normal method to scan the text for the <IMG> tag and get rid of it yourself before putting it in the JEditorPane using the setText() method. You can try something like this:
    public String removeImgTag(String text) {
       String tmp=text.toLowerCase();
       int i=tmp.indexOf("<img");
       if (i<0) return text;
       int j=tmp.substring(i).indexOf(">");
       return tmp.substring(0,i-1)+tmp.substring(i+j);
    };o)
    V.V.

  • Replace function for HTML tags

    Hie Guys,
    I would like to get rid of the HTML tags from a column/object in my report using the "Replace" function. Basically, I want to replace whatever the content is between "<" & ">" i.e. the opening and closing tags. I know I can use the "Pos" function to identify the position of "<" & ">", but I am not sure exactly how to achieve this in Webi. FYI -  "Read content as HTML" & "Read content as Hyperlink" did not resolve the issue. Can anyone please help? Thanks.

    Hi Jeewan,
    It will be very tedious to do this at Webi level.
    I have tried below example. It might help you to work around your issue; however, not completely:
    1. Created an Excel and inserted single value in first column as:
    <html><b>this is yuvraj</b></html>
    2. Used it as source and created a Webi report in Rich client.
    3. Applied SubStr recursively using Pos function and created below variables:
    test : =Substr([column_1]; Pos([column_1];">")+1;Length([column_1]))
    test1: =Substr([test]; Pos([test];">")+1;Length([test]))
    test2 : =Substr([test1]; 0;Pos([test1];"<")-1)
    The output has been attached.

  • How to replace an html br tag in the field to a carriage return?

    Hi All,
    I have a requirement to replace the <<br>> tag in the text field with a carriage return character "
    Currently the data in the Comments field looks like :
    "20100627 -115541 SECURITY WILL MEET AT MAIN ENTERANCE"<<<br>>"20100627 -115605 Officer notified: ALPHA : DF-10-011891; ST VINCENTS HOSPITAL, ST VINCENTS HOSPITAL, SAINT VINCENTS HOSP, MERRION RD, MERRION, BOOTERSTOWN, DUBLIN; FIRE/ALARM ACTIVATION;'<<br>>'20100627 -115609 PDA MOBILISED AFTER AMENDMENT VIN1'<<br>>'20100627 -"
    The <<br>> break tag was used for HTML purpose and now I would like to replace it with a carriage return character for BI Publisher report.
    Appreciate3 your help.
    Regards
    B
    Edited by: Bees on Jul 21, 2010 4:36 AM

    I downloaded your html template and it works fine for that template and the xml, but in my case it is not working. I need to assign the template just for one field called "Comments" where I need <<br>> tag to work.
    I modified the html as you suggested with the Tidy software, here is what I have done may be you can help me here. I very much appreciate your help.
    1. I have imported the template with the tag <<?import:file:///C:/dfb/biPub/code/htmlmarkup.xsl?>> and it works fine.
    2. Assigned the xsl - assign-template to the comments field.
    <xsl:apply-templates select="Fact._COMMENTS_" />
    *** IncidentsFact_._COMMENTS is the field name where it has <<br>><</br>> embedded into the comments data.
    Edited by: Bees on Jul 30, 2010 6:29 AM

  • Replacing HTML tags using HTMLEditorKit etc.

    Hi
    Not sure if this is the best place to ask this. I've searched without finding much.
    Basically I am trying to create a HTML template system for output. User's can change the templates to change the program output.
    The templates are basic HTML with custom tags inserted, that reside in a templates directory. For example, a simple template might be:
    <html><body>
    <table width="100%"><tr><td width="25%">Here is the output:</td>
    <td> <insertOutputHere> </td>
    </tr></table>
    </body></html>
    ^^ Users would be able to edit these template .htm files to affect the output .htm files. For instance, changing where the <insertOutputHere> tag is, or formatting the table it is output to.
    I am using the Swing HTMLDocument, HTMLWriter, HTMLEditorKit classes to load and parse the .htm files, iterate the tags and replace any custom tags (defined in code) with the program output. I have been able to locate these custom tags no problem, but I don't know how to replace this tag entirely with my output (Which will be formatted HTML string). I have been trying to use the insertBefore, insertAfter methods with limited success. In particular I have an 'include' custom tag which includes other files by recursion - it works except the <include> tag is not removed, and depending on which insert method I use, it usually goes into an infinite loop of parsing the <include> tag WITHOUT removing it, then picking it up again when its done.
    Basically I'm looking for any advice as to how to go about COMPLETELY REPLACING these tags with a well structured HTML string. I can post some code if need be but I barely comprehend what I've done, LOL.
    TIA

    I've looked over my mess of comments :)
    setOuterHTML is what I was previously using and it was quite unpredictable at times, as far as I could tell it is very strict with it's requirements for structured HTML (EG no floating line breaks, everything must be "paragraph-ised" which b0rks up the layout) and I can't rely on anyone using/extending these classes to write well structured HTML.
    I remember the problems being quite odd, such as the output for one custom tag being displayed twice for some and not at all for others, and while it isn't critical data, it was still displayed in a way that it could be interpreted as correct - I just knew it wasn't.
    So I dropped setOuterHTML to try insertAfterEnd - this leaves the tags in there and, like roughly explained above, it would pick up tags infinitely because they were not being replaced.
    Here is a relevant method to give a better idea of what I've done:
           public HTMLDocument parseHTMLfile(String filename, Custom_HTML_Tag tags[]) {
          //create a document
             HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
             fileDepth++;
             try {
             //read in the file
                BufferedReader rd = new BufferedReader(new FileReader(filename));
                kit.read(rd, doc, 0);
                if (tags != null) {
                //replace tags with page content
                   ElementIterator it = new ElementIterator(doc);
                   Element e;
                   while ((e = it.next()) != null) {
                   //look for includes
                      if (e.getName().equals("include")) {
                         if (fileDepth >= 5){
                         //WARNING:
                            System.out.println("fileDepth has reached 5, include may be recursive. aborting.");
                            continue;
                         String href = (String)e.getAttributes().getAttribute(HTML.Attribute.HREF);
                      //grab parent of current file (IE the folder in which it sits)
                         File f = new File(filename);
                         String include = f.getParent() + sep + href;
                         f = new File(include);
                         if (f.exists()) {
                            HTMLDocument htmld = parseHTMLfile(include, tags);
                            StringWriter sw = new StringWriter();
                            HTMLWriter w = new HTMLWriter(sw, htmld);
                            w.write();
                            doc.setOuterHTML(e, sw.toString());
                         else {
                         //couldnt find include file - warning
                      for (int i=0; i < tags.length; i++) {
                         if (e.getName().equals(tags.getName())) {
    //doc.setOuterHTML(e, tags[i].getText());
    doc.insertAfterEnd(e, tags[i].getText());
    //System.out.println("found tag: " + tags[i].getName() + ": " + tags[i].getText());
    catch (BadLocationException ble) {// cant happen?
    System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; BadLocationException");
    System.err.println(ble);
    catch (FileNotFoundException fnf) {
    System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; File not found");
    //System.err.println(fnf);
    catch (IOException ioe) {
    System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; I/O Error:");
    System.err.println(ioe);
    fileDepth--;
    return doc;
    setInnerHTML kills it with the 'Can not set inner HTML of a leaf' error
    Thanks

  • Replace everything except in html tags

    I have this little piece of code hilighting words in search
    results, however, it obviously replaces text in html tags as well
    and I want it to omit all html. I've also noticed that
    replacenocase replaces the case of my words...while it does search
    for words no matter the case, I sure wish it wouldn't replace the
    case of the original text. Any tips would be greatly appreciated.
    <cfset variables.hiliteSummary =
    ReplaceNoCase(siteSearch.summary,url.criteria,"<span
    class=searchHilite>#url.criteria#</span>","ALL")>

    to fix your issue with case, use a rereplace and
    backreferences:
    rereplaceNoCase(siteSearch.summary, '(#url.criteria#)',
    '<span class="searchHilite">\1</span>', 'all')

  • How do I strip out all HTML tags except for safe ones I designate?

      // FLAG ALL INCIDENTS OF LEGITIMATE TAGS BY CONVERTING <..> TO <!..!>
      for (int i = 0; i < parseVector.size(); i++) {
       this.content =
        this.content.replaceAll("<(/?)(" + (String)parseVector.elementAt(i) + "[\\s\\t=]+[^>]*)>",
                       "\\<!$1$2!\\>");
      }I have a Vector of HTML string text consisting of things like:
    {"i", "b", "u", "blockquote", "font"}
    And within this.content, which contains HTML, I want to strip out all HTML except for certain "safe" tags.
    Problem is, my code fails to do just that.. while <img..> is gone, so is <i> and I want to keep the latter.
    I feel the problem is in my regular expression pattern within this.content.replaceAll() method, but maybe I'm wrong. What do you say?
    Entire code can be found in http://www.myjavaserver.com/~ppowell/HTMLParser.java
    Thanx
    Phil

    Let me give you an example of what I want:
    I understand what you want... I don't see how the code that you posted is supposed to that.
    The best advice I can give is that a for loop is not part of the equation here. You will need to do it in one regex I think. Because if what you are doing there is saying replace all the tags that aren't <i> on one loop and replace all the tags that are not <b> in another loop guess what is happening?
    On the first pass you don't replace the <i> tags but you do replace the <b> tags. On the next pass you replace <i> tags because they don't match the <b> etc.
    You see?
    So I think you need to do this all in one regex where the starting portion of the tag is NOT one of the set that you want to keep.

Maybe you are looking for

  • How ATTACH multiple files from different folders in one ATTACH 'session'?

    Hi, In Mac Mail, I often have to attach 2 or 3 separate files, all from different folder locations on my hard drive. This requires clicking attach, selecting file 1 and clicking OK, which closes the Attach dialog. Then I have to do it again 2 times f

  • Display won't work in Classic! WHY?

    I tried starting OS 9 Classic on my G4 using the clear plastic Apple display. The screen was Black. I finally got my screen back up had to kook up a different monitor to fix things. For the longest i just haven't used OS 9 BUT I need to open some old

  • Editing clip in Audition opens up older version of Audition

    So whenever I select a track in CS6 to edit in Audition, it opens up 5.5 and not Audition 6. I just recently reinstalled all of them, so its doing this after a reinstall. Any tips?

  • Flash unable to import mx.graphics.codec

    Hi I am having a wied issue with flash flash is unable to import mx.graphics.codec error  1172 a definition could not be found do I have to download this codec from some place, it seem to me that they must be here thanks

  • Need a little help.... not major....but am unsure I have...

    Need a little help.... not major....but am unsure I have the 2.4 GHz Wireless-G Broadband Router Model WRT54G version 2 I had bought some time ago (over year and a half) and never really had it hooked up since I have been moving from place to place.