Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
As Corion pointed out, (.*) does not function as a capture inside \Q...\E.... but note, also, that if it did, so too would the empty pair of parentheses immediately after "cs". AFAIK (and as far as I can tell from some limited experimentation after reading your post), the regex engine does not squawk (OUT LOUD!) about an empty capture spec.

What's more, you are already using escape characters -- in the string assigned to $line.Have you carefully considered your requirement that the regex not use the same tool?

Updated with code and output after of some testing while *STILL* making myself crazed: Anyone see a problem here?
(and, please, find no fault with those who cast 3 upvotes, before I committed this [questionable] update)


#!C:/perl/bin use strict; use warnings; use vars qw ($line $line1 ); $line= "onmouseout=\"cs()\">Otani <b>Restaurant</b> &amp; <b>Sushi</b> + Bar: <b>Columbus</b> <b>Ohio</b> DiningGuide \ <b>Restaurant</b>...</a>csdkjfhasdkjghlkjhdfgkj"; print "Demonstrate that line_extending_slash after 'Dining Guide ' is +not an issue:\n" . $line . "\n\n"; &OP_mod ($line); &one ($line); &two ($line); &Corion ($line); # and a final test: $line1 = "now is the time for all good men..."; if ( $line1 =~ /()/ ) { print "\n In 'final test' at line 21, \$1 is : |$1| \n"; } else { print "no match on empty parens\n"; } print "done\n"; exit (1); ######### sub OP_mod # after Corion, placing \QE differently and using || fo +r match delimiters { if ( $line =~ m|onmouseout=\Q"cs()"\E>(.*)</a>| ) { print "\t \$1 is: $1\n"; } else { print "No match in sub OP_mod\n"; } return (); } sub one { if ( $line =~ m|onmouseout=.cs.{3}>(.*)</a>| ) # 3 chars between "cs" + and ">" -- (, ), and escaped double_quote { print "\t \$1 is: $1\n"; } else { print "No match in sub one\n"; } return (); } sub two { if ( $line =~ m|cs().>(.*)\Q</a>\E| ) { print "\t,in sub two, \$1 is: $1 and \$2 is $2\n"; } else { print "No match in sub two\n"; } return; } sub Corion { if ( $line =~ m@\Qonmouseout="cs()">\E(.*)\Q</a>\E@ ) { print "in subCorion, \$1 is: $1\n"; } else { print "No match in subCorion\n"; } # next two lines, uncommented, return exact original of $line, less th +e trailing line_extending_slash $line =~ m@\Qonmouseout="cs()">\E(.*)\Q</a>\E@; print "\n -- \$line after exact replica of Corion's: $line \n"; return; } =HEAD output under w2k, perl v 5.8.6, with CLI (DOS) window set to wid +th = 255 C:\_perl\pl_test>perl r1109.pl Demonstrate that line_extending_slash after 'Dining Guide ' is not an +issue: onmouseout="cs()">Otani <b>Restaurant</b> &amp; <b>Sushi</b> Bar: <b>C +olumbus</b> <b>Ohio</b> DiningGuide <b>Restaurant</b>...</a>csdkjfhasdkjghlkjhdfgkj No match in sub OP_mod No match in sub one No match in sub two No match in subCorion -- $line after exact replica of Corion's: onmouseout="cs()">Otani <b> +Restaurant</b> &amp; <b>Sushi</b> Bar: <b>Columbus</b> <b>Ohio</b> Di +ningGuide <b>Restaurant</b>...</a>csdkjfhasdkjghlkjhdfgkj In 'final test' at line 21, $1 is : || done C:\_perl\pl_test> =cut

In reply to Re: simple regEx by ww
in thread simple regEx by jithoosin

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 having a coffee break in the Monastery: (7)
As of 2024-04-19 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found