Here is an example I’m using:
Pattern p = Pattern.compile(".*<img[^>]*src=\"([^\"]*)", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher("<img src=\"aoeuaoeu\"/>");
m.find();
System.out.println(m.group(1));
So the output of this code is: aoeuaoeu.
What do I need to put in the parentheses to search something in a text, like in the example?
The first parameter of the pattern is a regular expression. It must conform to a regular expression language, a widely used way to describe such patterns.
Although the fine details of regular expressions are very important to understand, and are often subjects of lengthy college courses, you can learn the basics by following a simple tutorial [link], following numerous examples, and trying your hand at writing regular expressions for your particular purposes.
There are many implementations of regular expression engines, with widely different capabilities. To learn the particulars of the Java “dialect” of regular expressions, follow the documentation of the
Patternclass.