Question

In: Computer Science

write a regular expression that will, using capturing groups, find: last name first name middle name...

write a regular expression that will, using capturing groups, find:

  • last name
  • first name
  • middle name (if available)
  • student ID
  • rank
  • home phone
  • work phone (if available)
  • email
  • program (i.e., S4040)
  • grade

Replace the entire row with comma-delimited values in the following order:

  • first name,middle name,last name,program,rank,grade,email,student ID,home phone,work phone
Example substitution string for the first student

Solutions

Expert Solution

import java.util.regex.*;
public class Main
{
        public static void main(String[] args) {
                String input = "Jane,V,Quinn,S4040,SO,B,[email protected],Q43-15-5883,318-377-4560,318-245-1144,Y";
        String regexp = "([A-Za-z]+),+([A-Za-z]+),+([A-Za-z]+),+([0-9A-Za-z]+),+([A-Za-z]+),+([A-Z]),+([0-9A-Za-z@.]+),+([0-9A-Za-z-]+),+([0-9-]+),+([0-9-]+)";
        
        Pattern pattern = Pattern.compile(regexp);
        Matcher matcher = pattern.matcher(input);
        matcher.find();
        System.out.println("Firstname  : " + matcher.group(1));
        System.out.println("Middlename : " + matcher.group(2));
        System.out.println("Lastname: " + matcher.group(3));
        System.out.println("Program: " + matcher.group(4));
        System.out.println("Rank: " + matcher.group(5));
        System.out.println("Grade: " + matcher.group(6));
        System.out.println("Email: " + matcher.group(7));
        System.out.println("Student ID: " + matcher.group(8));
        System.out.println("Home phone: " + matcher.group(9));
        System.out.println("Work Phone: " + matcher.group(10));
        }
}

Output:

Firstname : Jane
Middlename : V
Lastname: Quinn
Program: S4040
Rank: SO
Grade: B
Email: [email protected]
Student ID: Q43-15-5883
Home phone: 318-377-4560
Work Phone: 318-245-1144


I have done the program in Java.


Related Solutions

java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Step 1: Capturing the input The first step is to write a functionGetInput()that inputs the expression...
Step 1: Capturing the input The first step is to write a functionGetInput()that inputs the expression from the keyboard and returns the tokens---the operands and operators---in a queue. You must write this function. To make the input easier to process, the operands and operators will be separated by one or more spaces, and the expression will be followed by #. For example, here’s a valid input to your program: 6 4 15 * – # Back in Codio, modify “main.cpp”...
Write a regular expression, using the regular expression syntax used by lex, that matches any finite...
Write a regular expression, using the regular expression syntax used by lex, that matches any finite decimal representation of a nonnegative real number.
1. Write the SQL code required to list the employee number, first and last name, middle...
1. Write the SQL code required to list the employee number, first and last name, middle initial, and the hire date. Sort your selection by the hire date, to display the newly hired employees first. 2. Modify the previous query and list the employee first, last name and middle initial as one column with the title EMP_NAME. Make sure the names are listed in the following format: First name, space, initial, space, last name (e.g. John T Doe). Hint: use...
Pattern matching using python3 re module Write a regular expression that will find out all the...
Pattern matching using python3 re module Write a regular expression that will find out all the words that ends with 4 consecutive vowels at the end. Example: import re f=open("/usr/share/dict/american-english",'r') pattern='a[a-z]*d$' words=f.readlines() matchlist=[word for word in words if re.match(pattern,word)] =============================== Generate random string follow a specific pattern You will take a username and ask user for the password. User has to enter a strong password in order to create his or her account. The criteria for strong password is, a)...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
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.
How do I get the first initial of a first, middle, and last name? Also when...
How do I get the first initial of a first, middle, and last name? Also when I look to count characters in the name I want to be abel to count the spaces in-between the names how can i do this?
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT