885 links
  • Links Lounge
  • Home
  • Login
  • RSS Feed
  • Tag cloud
  • Picture wall
  • Daily
Links per page: 20 50 100
page 1 / 1
  • Note : regex pour matcher les balises HTML et les attributs - Le Hollandais Volant

    Ah oui les regex. Toujours galère en particulier pour parser du HTML; Je me demande si Le Hollandais Volant nous montrera un exemple d'utilisation.

    Personnellement, j'ai testé son script en utilisant le code de son article comme exemple (éhéh !). J'ai quelques balises de titre qui restent, mais c'est peut-être fait exprès... ?

    <div id="main">
        <section id="midle">
            <div id="posts">
            <article class="itembloc link" id="20130322003640">
        <hgroup class="post-hgr links-hgr">
            <h2 class="link-titre"><a href="index.php?mode=links&id=20130322003640">#5292</a> - <a href="http://lehollandaisvolant.net/?mode=links&id=20130322003640">Note : regex pour matcher les balises HTML et les attributs</a></h2>
            <h3 class="link-date">Aujourd’hui à 00:36:40</h3>
        </hgroup>
        <div class="post-cnt links-cnt">
            "#<\s*/?(?:[a-zA-Z-]+)(?: (?:\s*\w+=(['\"])(?:(?!\g{1}).|(?:(?<=\\\)\g{1}))+\g{1})*(?:\s*\w*\s*))?/?>#S"<br />
    <br />
    (en php, en gros : utiliser dans un preg_replace() et les remplacer par une chaine vide agira comme striptags().)<br />
    <br />
    (oui, les attributs peuvent contenir un « > » ou un « < », par exemple en JS : « 2<=4 », et c’est chiant).<br />
    <br />
    Un peu de doc complémtentaire :<br />
    <a href="http://www.regular-expressions.info/refadv.html">http://www.regular-expressions.info/refadv.html</a><br />
    <a href="http://stackoverflow.com/questions/6050427/regex-problem-with-backreference-in-pattern-with-preg-match-all/6051114#6051114">http://stackoverflow.com/questions/6050427/regex-problem-with-backreference-in-pattern-with-preg-match-all/6051114#6051114</a> (commentaire intéressant)<br />
    <a href="http://blog.lilhoot.eu/regex-et-preg-assertions-avant-arriere-lookahead-lookbehind-assertions-recuperer-les-chaines,a3">http://blog.lilhoot.eu/regex-et-preg-assertions-avant-arriere-lookahead-lookbehind-assertions-recuperer-les-chaines,a3</a> (en français, très intéressant et très clair)
        </div>
    </article>
    </div> <!-- end postS -->

    Devient :

    <h2 class="link-titre"> #5292  -  Note : regex pour matcher les balises HTML et les attributs </h2>
    <h3 class="link-date">Aujourd’hui à 00:36:40</h3>
    
    "#<\s*/?(?:[a-zA-Z-]+)(?: (?:\s*\w+=(['\"])(?:(?!\g{1}).|(?:(?<=\\\)\g{1}))+\g{1})*(?:\s*\w*\s*))?/?>#S" 
    
    (en php, en gros : utiliser dans un preg_replace() et les remplacer par une chaine vide agira comme striptags().) 
    
    (oui, les attributs peuvent contenir un « > » ou un « < », par exemple en JS : « 2<=4 », et c’est chiant). 
    
    Un peu de doc complémtentaire : 
     http://www.regular-expressions.info/refadv.html  
     http://stackoverflow.com/questions/6050427/regex-problem-with-backreference-in-pattern-with-preg-match-all/6051114#6051114  (commentaire intéressant) 
     http://blog.lilhoot.eu/regex-et-preg-assertions-avant-arriere-lookahead-lookbehind-assertions-recuperer-les-chaines,a3  (en français, très intéressant et très clair)
    <!-- end postS -->
    Fri 22 Mar 2013 09:15:56 AM CET - permalink -
    - - - http://lehollandaisvolant.net/?mode=links&id=20130322003640
    HTML PHP Regex Sanitize
Links per page: 20 50 100
page 1 / 1
Shaarli - The personal, minimalist, super-fast, no-database delicious clone by the Shaarli community - Help/documentation