in reply to Calculated position incorrect when using regex in text file that also contains binary info
Works fine for me:
use strict; use warnings; use Test::More; my $pdf = <<'EOT'; /CapHeight 667 >> endobj 1 0 obj << /Subtype /Type1C /Length 1194 2 0 obj >> stream 3 0 obj BXTBMO+URWTypewriterTOT-LigNar %øøø ûûúNú% Lm ÷/÷>¦ 7D(URW)++,Copyright 2003 by (URW)++ Design & Development/FSType +4 def - B F H J O S r ¡S»OÑûb싸øո÷Å÷°Àø÷K{zwû }}û}øÔ{ûp{|}¾}ü}}X{|}øMÅ}µ÷g°÷4µµÄ÷¢Áø£zÜ|k}÷΃ªr¨°m\\Hf|oaviZb +{~Ȕ¸¬×©v¡¤tuJY<Z{hYso^P4ÇUîἬڬ.÷!±´e~L~u^r^sP a±ÊÕį÷ .û.û-Þ/÷ÖÀ¢º®¥}wH{Ue?^±lr©zº±´«¼¥©©¤´º±|p¤¨l^dòûIµ÷#µø+ ´oµ±Ã÷ÐÁ¬ø.uovat_wJY¨¾{~~zuj¤vo¬º~Ѹ¯§¶Ïø ²|3{zI\\ÎsO°8=1û\'û#Ý-÷¹¯®û- +÷Ø·®|l©gfAGfsken^uZÛ÷ ÊÖï´ø´öÜÞÜKÁè÷.øLz4|~±}ûê}}e|~÷6|k}ðløãuyyuux¡¡¡¢ytñ´ø´oµ +ðÁ÷ÁØ÷/øLz3|~²}ûê}}d|~÷=|e}÷i¸ïÀÉàٵ_9û}}e|~÷=|d}÷îSÁ%>TfIu ´ +ø´oµðÁÐ÷/øLz3|~²}ûê}}d|~÷M|U}÷\\ۥº¢0©}rec{rqyy{wød÷K¶ à ¶ Ò ÷ø\\ endstream endobj 4 0 obj << /Length 422 >> EOT my @tests = ( { no => 1, start => 26, end => 33 }, { no => 2, start => 68, end => 75 }, { no => 3, start => 87, end => 94 }, { no => 4, start => 1315, end => 1322 }, ); plan tests => 2 * @tests; for my $t (@tests) { my $result = $pdf =~ qr/^$t->{no} 0 obj/m; is $-[0], $t->{start}, "No $t->{no} first match starts at $t->{sta +rt}"; is $+[0], $t->{end}, "No $t->{no} first match ends at $t->{end}" +; }
Perl 5.20.3 on Linux
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Calculated position incorrect when using regex in text file that also contains binary info
by geertvc (Sexton) on Jun 17, 2020 at 05:35 UTC | |
by hippo (Archbishop) on Jun 17, 2020 at 08:20 UTC | |
by Anonymous Monk on Jun 19, 2020 at 02:29 UTC |