Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: perl indication of end of string already matched

by Marshall (Canon)
on Jun 08, 2020 at 21:41 UTC ( [id://11117832]=note: print w/replies, xml ) Need Help??


in reply to perl indication of end of string already matched

I am confused also. This appears to be a very contrived example. Can you show some code closer to your actual application?

For your regex, just keeping track of last vs curr pos would seem to do it. $ matches when pos does not advance.

use warnings; use strict; my $str = "abc"; my $last_pos =0; while ($str =~ m/.|$/gc) { my $curr_pos = pos($str); printf("1: %d", $curr_pos); ($curr_pos == $last_pos) ? print " EOString\n" : print "\n"; $last_pos = $curr_pos; } __END__ 1: 1 1: 2 1: 3 1: 3 EOString
For character by character processing of a string, substr() and it's buddies are appropriate, not regex. An example showing more of what you are really trying to accomplish would be helpful.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117832]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-16 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found