Search code examples
javajsoup

Getting Image using Jsoup


Please help me understand this expression

Elements images = document.select("img[src~=(?i)\\.(png|jpe?g|gif)]"); 

I don't understand the this part:

document.select("img[src~=(?i)\\.(png|jpe?g|gif)]");

I am currently making a program that will download manga image online.


Solution

  • The part of the expression you are asking about is called a Regular Expression.

    To quote Wikipedia,

    A regular expression is a sequence of characters that define a search pattern

    In your use case, the regular expression at hand is used to identify all img tags that have a src attribute with a file name that has an extension of .png or .jpg/.jpeg or .gif.

    You can test it out using this tool