Question

create a regular expression in Java that defines the following. A "Stir" is a right brace...

create a regular expression in Java that defines the following.

A "Stir" is a right brace '}' followed by zero or more
lowercase letters 'a' through 'z' and decimal digits '0'
through '9', followed by a left parenthesis '('.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Test
{
   public static void main(String args[])
   {

//here we are declaring the pattern for regex according to given rules
       Pattern mypattern = Pattern.compile("[}][a-z0-9]+[(]");

// we are creating a matcher class object which lookasfor the pattern defined in the given input string.
       Matcher m1 = mypattern.matcher("}abc897(");

//this loop will print the pattren beginning and ending of the pattern in the given input string
       while (m1.find())
       {
           System.out.println("In }abc897( Pattern is found from "+m1.start()+" to "+(m1.end()-1));
       }

// this will check whether the given input string matches with the pattern exactly or not
       if(Pattern.matches("[}][a-z0-9]+[(]", "{0a)")==false)
       {
       System.out.println("In abc897) Pattern match not found.");
       }
   }
}

Time(sec) 0.08 Memory(MB): 56.8359 Output: Copy In Jabc897( Pattern is found from e to 7 In abc897) Pattern match not found.

Add a comment
Know the answer?
Add Answer to:
create a regular expression in Java that defines the following. A "Stir" is a right brace...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT