Question

In: Computer Science

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 '('.

Solutions

Expert Solution

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.");
       }
   }
}


Related Solutions

: Create a Java program that will accept a regular expression and a filename for a...
: 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 need to be accepted: + - one or more of the following character (no groups) * - zero or more of the following character (no groups) [] – no negation, no character spans – the...
Define a regular expression in JAVA for the following An "Ent" is an at sign '@',...
Define a regular expression in JAVA for the following An "Ent" is an at sign '@', followed by one or more decimal digits '0' through '9' or uppercase letters 'R' through 'W', followed by an octothorpe sign '#'
1) Java uses a right brace to mark the end of all compound statements. What are...
1) Java uses a right brace to mark the end of all compound statements. What are the arguments for and against this design? 2) What a role does the symbol table play in a complier.
Brace, Inc., a regular corporation, owns 90% of West common stock. This year, Brace generated $60,000...
Brace, Inc., a regular corporation, owns 90% of West common stock. This year, Brace generated $60,000 taxable income before the dividend received deduction, including $10,000 dividend income from West. Brace's taxable income after special deductions is: options: A) $53,000 B) $58,000 C) $52,000 D) $50,000
Unix / Linux 16. Regular Expression: Given the following regular expression, provide a description of the...
Unix / Linux 16. Regular Expression: Given the following regular expression, provide a description of the intended match. ^[^A-Z] 17. Regular Expression: Given the following regular expression, provide a description of the intended match. [^^!] 18. Regular Expression: Given the following regular expression, provide a description of the intended match. ^.\{72\}$ 19. Regular Expression: Given the following regular expression, provide a description of the intended match. [A-Za-z0-9] 20. Regular Expression: Given the following regular expression, provide a description of the...
Create a java program that: - Has a class that defines an exception -Have that exception...
Create a java program that: - Has a class that defines an exception -Have that exception throw(n) in one method, and be caught and handled in another one. -Has a program that always continues even if incorrect data is entered by the user -has a minimum of 2 classes in it
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
Consider the following regular expression meta operators: ( ) [ ] { } . * +...
Consider the following regular expression meta operators: ( ) [ ] { } . * + ? ^ $ | \ For each of the following, give one example of strings which the regular expression would match. Describe (colloquially, in a manner that a non-technical person would understand) the set of strings that the pattern is designed to match. Each regular expression is enclosed in the pair of '/' characters below. [2 marks each] (a) /^[a-z][0-9]*\.$/ (b) /([0-9]+)\s\w+\s\1/
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”....
1. What is a regular expression? Write a regular expression that will detect “College” and “collegE”. 2. What is degree centrality? Create a graph of 4 vertices and compute the degree centrality of the vertices. 3. Compute internal and external community densities for a graph containing 6 nodes. You can create any graph of 6 nodes with at least 4 edges.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT