develooper Front page | perl.beginners | Postings from March 2022

Re: Can use perl for download photos from facebook?

Thread Previous | Thread Next
From:
Jim Gibson
Date:
March 20, 2022 13:10
Subject:
Re: Can use perl for download photos from facebook?
Message ID:
1638DF51-1845-4135-A57B-7F81292FD6D9@gmail.com
On Mar 19, 2022, at 7:17 PM, William Torrez Corea <willitc9888@gmail.com> wrote:
> 
> Here is the short code:
> 
> https://gist.github.com/adipasquale/2217595
> 

The regular expression in that program is not valid. You are using brackets […] incorrectly. The pattern [a-z] will match exactly one character in the range a-z. The pattern [a-z\/\.] will match one character in the range a-z or the backslash character ‘\’ or the forward slash character’/‘ or the period character ‘.’. Inside brackets you do not need to escape special characters, and if you want to match the ‘-‘ character, put it at the beginning or ending of the pattern string, e.g. [a-z-] will match a-z or ‘-‘.

Here is a regular expression that should do what you want:

	while ( /(https?:\/\/\S*?\.jpg)/g ) {

Here is another one that uses the m{} operator so you don’t have to escape the ‘/‘ characters and the /x modifier to allow you to insert whitespace and comments into the regular expression to make it more readable:

	while ( m{ ( https?:// \S*? .jpg ) }xg ) {

Either of these finds 47 links to .jpg files in your data document:

https://scontent.fmga3-1.fna.fbcdn.net/v/t39.30808-1/274490608_3202483196693292_7724900589789523726_n.jpg
...
   
Jim Gibson




Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About