{"id":9,"date":"2015-01-22T18:01:16","date_gmt":"2015-01-22T18:01:16","guid":{"rendered":"http:\/\/habett.fr\/wordpress\/?p=9"},"modified":"2015-01-22T18:01:16","modified_gmt":"2015-01-22T18:01:16","slug":"regexp-so-legit","status":"publish","type":"post","link":"https:\/\/habett.fr\/blog\/2015\/01\/regexp-so-legit\/","title":{"rendered":"Regexp so legit"},"content":{"rendered":"<p>Remue m\u00e9ninge sur un extracteur g\u00e9n\u00e9rateur de liens pour des Codes en code.<\/p>\n<div><\/div>\n<div>Voil\u00e0 donc un petit chunck de mon affreux linker par <a class=\"zem_slink\" title=\"Regular expression\" href=\"http:\/\/en.wikipedia.org\/wiki\/Regular_expression\" rel=\"wikipedia\">regex<\/a>:<\/div>\n<div><\/div>\n<div><span class=\"Apple-style-span\">foreach $natty (&lsquo;d\u00e9cret&rsquo;,&rsquo;loi&rsquo;,&rsquo;ordonnance&rsquo;) {<\/span><span class=\"Apple-style-span\"><br \/>\n<\/span><span class=\"Apple-style-span\">\u00a0\u00a0\u00a0\u00a0\u00a0(@possibles) = $text =~ \/($natty[^&lt;&gt;]{1,21}\\d\\d\\-\\d+)\/g;<\/span><span class=\"Apple-style-span\"><br \/>\n<\/span><span class=\"Apple-style-span\">\u00a0\u00a0\u00a0\u00a0\u00a0foreach $possible (@possibles) {<\/span><span class=\"Apple-style-span\"><br \/>\n<\/span><span class=\"Apple-style-span\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$text =~ s\/([^=&gt;])$possible([^&lt;\u00ab\u00a0])\/$1&lt;a href=\u00a0\u00bbhttp:\\\/\\\/perlpot.net\\\/cgi-bin\\\/r.cgi\\?what=$possible\u00a0\u00bb shape=\u00a0\u00bbexxo$natty\u00a0\u00bb&gt;$possible&lt;\\\/a&gt;$2\/;<\/span><span class=\"Apple-style-span\"><br \/>\n<\/span><span class=\"Apple-style-span\">\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><br \/>\n<span class=\"Apple-style-span\" style=\"color: #000000; font-family: Helvetica; font-size: medium;\">}<\/span><\/div>\n<div><span class=\"Apple-style-span\" style=\"color: #000000; font-family: Helvetica; font-size: medium;\">\u00a0<\/span><\/div>\n<div>Reste donc \u00e0 \u00e9crire le r.cgi qui r\u00e9pond.<\/div>\n<div><\/div>\n<div>\n<div>#!\/usr\/bin\/perl<\/div>\n<div>use CGI;<\/div>\n<div>use WWW::Mechanize;<\/div>\n<div>$q = new CGI;<\/div>\n<div>($natty,$numb) = $q-&gt;param(&lsquo;what&rsquo;) =~ \/(.*?)\\s.*?(\\d\\d\\-\\d+)\/;<\/div>\n<div>$natty =~ s\/\\W\/.\/g;<\/div>\n<div>$www = new WWW::Mechanize;<\/div>\n<div>$www-&gt;get(&lsquo;http:\/\/www.legifrance.gouv.fr\/initRechTexte.do&rsquo;);<\/div>\n<div>$www-&gt;form_number(1);<\/div>\n<div>($opt) = grep { $_ =~ \/$natty\/i } $www-&gt;content =~ \/&lt;option value=\u00a0\u00bb(.*?)\u00a0\u00bb\/g;<\/div>\n<div>$www-&gt;field(&lsquo;champNatureTexte&rsquo;,$opt);<\/div>\n<div>$www-&gt;field(&lsquo;champNumTexte&rsquo;,$numb);<\/div>\n<div>$www-&gt;submit();<\/div>\n<div>($url) = $www-&gt;content =~ \/&lt;li class=\u00a0\u00bbresultat1&Prime;&gt;.*?href=\u00a0\u00bb(.*?)\u00a0\u00bb\/s;<\/div>\n<div>$url =~ s\/^\\.\\\/\\.\/http:\\\/\\\/legifrance.gouv.fr\/;<\/div>\n<div>print \u00ab\u00a0Location: $url\\n\\n\u00a0\u00bb;<\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div>OK ?<\/div>\n<div class=\"zemanta-pixie\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Remue m\u00e9ninge sur un extracteur g\u00e9n\u00e9rateur de liens pour des Codes en code. Voil\u00e0 donc un petit chunck de mon affreux linker par regex: foreach $natty (&lsquo;d\u00e9cret&rsquo;,&rsquo;loi&rsquo;,&rsquo;ordonnance&rsquo;) { \u00a0\u00a0\u00a0\u00a0\u00a0(@possibles) = $text =~ \/($natty[^&lt;&gt;]{1,21}\\d\\d\\-\\d+)\/g; \u00a0\u00a0\u00a0\u00a0\u00a0foreach $possible (@possibles) { \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0$text =~ s\/([^=&gt;])$possible([^&lt;\u00ab\u00a0])\/$1&lt;a href=\u00a0\u00bbhttp:\\\/\\\/perlpot.net\\\/cgi-bin\\\/r.cgi\\?what=$possible\u00a0\u00bb shape=\u00a0\u00bbexxo$natty\u00a0\u00bb&gt;$possible&lt;\\\/a&gt;$2\/; \u00a0\u00a0\u00a0\u00a0\u00a0} } \u00a0 Reste donc \u00e0 \u00e9crire le r.cgi qui r\u00e9pond. #!\/usr\/bin\/perl use &hellip; <a href=\"https:\/\/habett.fr\/blog\/2015\/01\/regexp-so-legit\/\" class=\"more-link\">Continuer la lecture de <span class=\"screen-reader-text\">Regexp so legit<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-archives"],"_links":{"self":[{"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":1,"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":10,"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/posts\/9\/revisions\/10"}],"wp:attachment":[{"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/habett.fr\/blog\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}