Answer the question
In order to leave comments, you need to log in
Regular expressions. How to cut the desired text?
There is text like this:
<img id = "3" class="lazy" src="/media/a.jpg" data-original="/media/a.jpg" alt="text">
Answer the question
In order to leave comments, you need to log in
You can look towards sed. In this way
You can get the data-original value from your string
Это будет быстрее и проще регулярных выражений:
tag = '<img id = "3" class="lazy" src="/media/a.jpg" data-original="/media/a.jpg" alt="text">'
pos1 = a.index('data-original="') + len('data-original="')
pos2 = tag.index('"', pos1)
link = tag[pos1:pos2]
use Mojo::DOM;
my $text = '<img id = "3" class="lazy" src="/media/a.jpg" data-original="/media/a.jpg" alt="text">';
my $data_original = Mojo::DOM->new( $text )->find( 'img' )->map( attr => 'data-original' );
print "$_\n" foreach @$data_original;
import re
reg = re.compile(r"data_original=\"([A-Za-z./]+\.jpg)\"")
print(reg.findall("<img id = \"3\" class=\"lazy\" src=\"/media/a.jpg\" data-original=\"/media/a.jpg\" alt=\"text\">"))
Сама регулярка:
echo '<img id = "3" class="lazy" src="/media/a.jpg" data-original="/media/a.jpg" alt="text">' | perl -lne '/data-original="([^"]+)/; print "$1";'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question