java.util.regex.Matcher ক্লাস এমন একটি ইঞ্জিনকে প্রতিনিধিত্ব করে যা বিভিন্ন ম্যাচ অপারেশন করে। এই ক্লাসের জন্য কোন কনস্ট্রাক্টর নেই, আপনি java.util.regex.Pattern ক্লাসের matches() পদ্ধতি ব্যবহার করে এই ক্লাসের একটি অবজেক্ট তৈরি/প্রাপ্ত করতে পারেন।
appendTail() এই (Matcher) ক্লাসের পদ্ধতি একটি StringBuffer অবজেক্ট গ্রহণ করে এবং এতে ইনপুট সিকোয়েন্সের অক্ষর যোগ করে।
উদাহরণ
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AppendTail {
public static void main(String[] args) {
String str = "<p>This <b>is</b> an <b>example</b> HTML <b>script</b>.</p>";
//Regular expression to match contents of the bold tags
String regex = "<b>(\\S+)</b>";
//Creating a pattern object
Pattern pattern = Pattern.compile(regex);
//Matching the compiled pattern in the String
Matcher matcher = pattern.matcher(str);
StringBuffer sb = new StringBuffer();
matcher.appendTail(sb);
while (matcher.find()) {
System.out.println(matcher.group(1));
}
System.out.println("Contents of the StringBuffer: \n"+ sb);
}
} আউটপুট
স্ট্রিংবাফারেরis example script Contents of the StringBuffer: <p>This <b>is</b> an <b>example</b> HTML <b>script</b>.</p>