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
  • For this discussion, you will be working with regular expressions. Please create a regular expression that...

    For this discussion, you will be working with regular expressions. Please create a regular expression that requires passwords to begin with an uppercase letter, followed by five lowercase letters, followed by a one-digit number (0-9), and ending with one symbol (@, $, %, or &). You may use the index.htm file included with this discussion to test your regular expression. Note that the index.htm file contains HTML and JavaScript. To test your regular expression, simply assign your regular expression to...

  • Regular Expression processor in Java Overview: Create a Java program that will accept a regular expression...

    Regular Expression processor in Java Overview: Create a Java program that will accept a regular expression and a filename for a text file. The program will process the file, looking at every line to find matches for the regular expression and display them. Regular Expression Format The following operators are required to be accepted: + - one or more of the following character (no groups) * - zero or more of the following character (no groups) [] – no negation,...

  • NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! A) write a regular...

    NEED ASAP PLEASE WILL GIVE GOOD RATE RIGHT AWAY FOR ALL ANSWERS! A) write a regular expression (use regular expression syntax) to represent a floating point number, where the number begiywith an optional sign followed by at least 1 digit , followed by a decimal point and one or more other digits. Ex: -33.9 , +1.11919, 1.0 B) draw a dfsa to represent the regular expression

  • Let digit be [0-9] what does the following regular expression defines in Unix? a). [-]?(({digit}+)|({digit}*\.{digit}+)([eE][+-]?{digit}+)?) b)....

    Let digit be [0-9] what does the following regular expression defines in Unix? a). [-]?(({digit}+)|({digit}*\.{digit}+)([eE][+-]?{digit}+)?) b). [-+]?{digit}+ c). Give two examples for each of the above.

  • Write a PHP regular expression pattern that matches a string that satisfies the following description: The...

    Write a PHP regular expression pattern that matches a string that satisfies the following description: The string must begin with the (uppercase) letter A. Any three alphanumeric characters must follow. After these, the letter B (uppercase or lowercase) must be repeated one or more times, and the string must end with two digits.

  • please Answer the following regular expressions questions(also do number 9) Q4 Choose the pattern that finds...

    please Answer the following regular expressions questions(also do number 9) Q4 Choose the pattern that finds all filenames in which the first letters of the filename are astA, followed by a digit, followed by the file extension .txt. 1) astA[[:digit:]]\.txt 2) astA[[0-9]].txt 3) astA.\.txt 4) astA[[:digit:]].txt Q5 What's the difference between [0-z]+ and \w+ ? 1) The first one accepts 0 and z and the other doesn't. 2) The first one doesn't allow for uppercase letters. 3) The first one...

  • Regular Expressions Write a regular expression for numeric constants in C. These are octal, decimal, or...

    Regular Expressions Write a regular expression for numeric constants in C. These are octal, decimal, or hexadecimal integers, or decimal or hexadecimal floating-point values. An octal integer begins with 0, and may contain only the digits 0-7. A hexadecimal integer begins with 0x or 0X, and may contain the digits 0-9 and a/A-f/F. A decimal floating-point value has a fractional portion (beginning with a dot) or an exponent (beginning with E or e). Unlike a decimal integer, it is allowed...

  • using java create hash set that can for the file use a txt file: Hi my...

    using java create hash set that can for the file use a txt file: Hi my name is rick. (a) Read one word from the file. (b) Remove all non-alphanumeric characters from the word. A non-alphanumeric character is any character other than the lowercase and uppercase English letters, and the numerals 0 through 9. (c) Add the modified word to the hash set.

  • This is in Java Create a client class that does the following: Manually creates an instance...

    This is in Java Create a client class that does the following: Manually creates an instance of a binary expression tree that represents the following expression: (((5+2)*(2-1)/((2+9))+((7-2)-1))*8) Do this by using methods such as addRoot, addLeft, addRight, set, and attach. The element should be of type String Note that you are manually building this specific expression tree, the pseudo code might look something like: Create a LinkedBinaryTree Add “*” as the root to the tree Add “/” as the left...

  • Preliminaries For this lab you will be working with regular expressions in Python. Various functions for...

    Preliminaries For this lab you will be working with regular expressions in Python. Various functions for working with regular expressions are available in the re module. Fortunately, Python makes it pretty easy to check if a string matches a particular pattern. At the top of the file we must import the re module: import re Then we can use the search() function to test whether a string matches a pattern. In the example below, the regular expression has been saved...

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
ADVERTISEMENT