In: Computer Science
Write a JAVA code using regex methods and concepts The test string S should match the following requirements:
Please upvote if you like the answer, as it helps the community a lot.
Also if you have any doubts, feel free to ask in comments, we will reach you ASAP.
Solution:
CODE: MatchMyPattern.Java
import java.util.regex.Pattern;
import java.util.Scanner;
class MatchMyPattern
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print ("Enter Text to be Matched with the
pattern: ");
String S = sc.next();
System.out.print ("Text Match Result is: ");
System.out.println
(Pattern.matches("[^0-9][^aeiou][^bcDE][^\n\r\t\f
][^AEIOU][^.,]",S));
}
}
SAMPLE I/Os:
Enter Text to be Matched with the pattern: SILENT Text Match Result is: true
Enter Text to be Matched with the pattern: 0ILENT Text Match Result is: false
Enter Text to be Matched with the pattern: SiLENT Text Match Result is: false
Enter Text to be Matched with the pattern: SIDENT Text Match Result is: false
Enter Text to be Matched with the pattern: SIL NT Text Match Result is: false
Enter Text to be Matched with the pattern: SILEAT Text Match Result is: false
Enter Text to be Matched with the pattern: SILEN. Text Match Result is: false
Enter Text to be Matched with the pattern: SILENTS Text Match Result is: false