Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Help on using alternation grouping star versus dot star. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found