Search This Blog

Monday, July 14, 2025

Java Regular Expressions - Quiz

 What will be the output of this regular expression (Java) code?

1. /*

 2. * Code by Nancy K.A.N.

 3. */

 4. import java.util.regex.Matcher;

 5. import java.util.regex.Pattern;

 6.  

 7. public class RegexSubStringTest {

 8.     public static void main(String[] args) {

 9.         String str1 = "This is an example of 'Java Regular Exressions'";

10.         Pattern pattern = Pattern.compile("'(.*?)'");

11.         Matcher matcher = pattern.matcher(str1);

12.         if (matcher.find())

13.         {

14.             System.out.println(matcher.group(1));

15.         }

16.     }

17. }

18.  

Created by Nancy K.A.N.

@17:13 14-Jul-2025


Follow my YouTube channel: @CodeWithNancy



No comments:

Post a Comment