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...
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...
Write a simple phonebook using c++ that read text file name list.txt and has:  first name, last...
Write a simple phonebook using c++ that read text file name list.txt and has:  first name, last name, and phone number as the example: MIKEL BUETTNER 3545044 ENOCH BUGG 2856220 BRENDON LAVALLEY 433312 QUINTIN CREEK 5200413 JAMISON MILLETT 6243458 FLORENCIO PUMPHREY 3296862 DARRICK FREGOSO 6868442 TOBIAS GLASSMAN 6040564 and then ask the user to add a new contact first name, last name, and phone number and same the information into a file. Use array and pointer
1. How do I write a query that displays the name (concatenate the first name, middle...
1. How do I write a query that displays the name (concatenate the first name, middle initial, and last name), date of birth, and age for all students? Show the age with no decimal places, and only include those students who are 21 or older. Order by age, as shown below: (Hint: Use the TRUNC function. The ages may be different, depending on the date that the query is run.) SELECT S_FIRST || ' ' || S_MI || ' '...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT