I'm a little new at regular expression and my use of them is in JavaScript, so please bear with me. There are several regular expressions that can be used to replace all <div class="blockqte">...</div> tag-pairs with <pre>...</pre>. The content of this particular <div> pair contains no other <div>'s but does contain <span> tag pairs. Of course, all <div>'s that don't have the class="blockqte" attribute are left alone.
The three regexp that I've designed to do this in JavaScript are:
1. re = /<div class="blockqte">((?:[^<]|<\/?s)*)<\/div>/g;
2. re = /<div class="blockqte">((?:[^<]*|<\/?s)*)<\/div>/g;
3. re = /<div class="blockqte">((?:.|\n)*?)<\/div>/g;
Any one of these go with the statement:
str = str.replace(re, "<pre>$1</pre>");
My understanding and please correct me if I'm wrong, is that expression number 3 is inefficient since it leaves the grouping with each of its evaluations to check the remainder of the expression (i.e. </div>). However, in 1 and 2 the group is left only with the first failure in matching all of its alternatives. That seems to make 1 and 2 better choices and it's here that I'm not sure of the advantages of one over the other. Can any one help with this?
By the way if there are better ways to do all this, I would much appreciate the advice and any clarifications. Thank you in advance.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.