কম্পিউটার

জাভা রেগুলার এক্সপ্রেশনে সাব-এক্সপ্রেশন (?:re)


সাব এক্সপ্রেশন/মেটাচ্যারেক্টার “(?:re) ” মিলিত টেক্সট মনে না রেখে রেগুলার এক্সপ্রেশন গ্রুপ করে।

উদাহরণ

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PatternExample {
   public static void main(String args[]) {
      //Reading String from user
      System.out.println("Enter a String");
      Scanner sc = new Scanner(System.in);
      String input = sc.next();
      String regex = "(?:[0-9])";
      //Compiling the regular expression
      Pattern pattern = Pattern.compile(regex);
      //Retrieving the matcher object
      Matcher matcher = pattern.matcher(input);
      //verifying whether match occurred
      boolean bool = matcher.find();
      if(bool) {
         System.out.print("Match found");
      } else {
         System.out.print("Match not found");
      }
   }
}

আউটপুট

Enter a String
9848022338
Match found

  1. জাভাতে রেগুলার এক্সপ্রেশন \D মেটাক্যারেক্টার

  2. জাভাতে রেগুলার এক্সপ্রেশন \S মেটাক্যারেক্টার

  3. নিয়মিত এক্সপ্রেশন ব্যবহার করে জাভাতে একটি স্ট্রিং থেকে লিডিং জিরোগুলি সরান

  4. জাভা রেগুলার এক্সপ্রেশন ব্যবহার করে স্ট্রিং থেকে সংখ্যা বের করুন