Question

Write a statement that creates a RegExp object that remembers the first and last name, but...

Write a statement that creates a RegExp object that remembers the first and last name, but does not remember the title. Using the RegExp object's exec() method, assign the result variable with the remembered first and last name of the string userName.

var userName = "Dr. Greg House"; // Code will also be tested with "Mr. Howard Wolowitz"

/* Your solution goes here */

console.log(result[1] + " " + result[2]);

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

Code for Dr. Greg House

var userName = "Dr. Greg House"; // Code will also be tested with "Mr. Howard Wolowitz"

//use exec() method

var result = /[A-Za-z.]+\s([A-Za-z]+)\s([A-Za-z]+)/i.exec(userName)

console.log(result[1] + " " + result[2]);

Code Screenshots:

Complete Code with HTML:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script>
var userName = "Dr. Greg House"; // Code will also be tested with "Mr. Howard Wolowitz"

//use exec() method

var result = /[A-Za-z.]+\s([A-Za-z]+)\s([A-Za-z]+)/i.exec(userName)

console.log(result[1] + " " + result[2]);

</script>
</body>
</html>

Code Screenshots:

Output Screenshots:

Code for Mr. Howard Wolowitz

var userName = "Mr. Howard Wolowitz"; // Code will also be tested with "Mr. Howard Wolowitz"

//use exec() method

var result = /[A-Za-z.]+\s([A-Za-z]+)\s([A-Za-z]+)/i.exec(userName)

console.log(result[1] + " " + result[2]);

Code Screenshots:

Complete Code with HTML:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script>
var userName = "Mr. Howard Wolowitz"; // Code will also be tested with "Mr. Howard Wolowitz"

//use exec() method

var result = /[A-Za-z.]+\s([A-Za-z]+)\s([A-Za-z]+)/i.exec(userName)

console.log(result[1] + " " + result[2]);

</script>
</body>
</html>

Code Screenshots:

Output Screenshots:

Hope it helps, if you like the answer give it thumbs up. Thank you.

Add a comment
Know the answer?
Add Answer to:
Write a statement that creates a RegExp object that remembers the first and last name, but...
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
  • only in javascript 1.Define a method named roleOf that takes the name of an actor as...

    only in javascript 1.Define a method named roleOf that takes the name of an actor as an argument and returns that actor's role. Ex: roleOf("Keira Knightley") returns "Elizabeth Swann". Hint: A method may access the object's properties using the keyword this. Ex: this.cast accesses the object's cast property. var movie = { // Code will be tested with different actors and movies name: "Pirates of the Caribbean: At World's End", director: "Gore Verbinski", composer: "Hans Zimmer", cast: { "Johnny Depp":...

  • Write a program that separately prompts the user for a first name and last name and...

    Write a program that separately prompts the user for a first name and last name and outputs a string containing the following information, in order: a. First letter of the user's name. b. First five letters of the user's last name. c. A random two-digit integer You must construct the desired string ensuring all characters are lowercase; output the identification string accordingly. Assume the last name contains at least 5 characters. You must use the Random (java.util.Random) class to generate...

  • Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean)...

    Create a class “Person” which includes first name, last name, age, gender, salary, and haveKids (Boolean) variables. You have to create constructors and properties for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from a “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the peoples information from “PersonInfo.txt” file and saves them into the array. In C# Give the user the ability to...

  • Write a class called Course_xxx that represents a course taken at a school. Represent each student...

    Write a class called Course_xxx that represents a course taken at a school. Represent each student using the Student class from the Chapter 7 source files, Student.java. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called roll that prints all students in the course. Create a driver class...

  • 1. Do the following a. Write a class Student that has the following attributes: - name:...

    1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...

  • JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. T...

    JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. The timer should show "count: the beginning and increase the number by 1 in every one second, and so on. o" at .3 A Timer - × A Timer Count: 0 Count: 1 (B) After 1 second, the GUI Window (A) Initial GUI Window According to the...

  • Last picture is the tester program! In this Assignment, you will create a Student class and...

    Last picture is the tester program! In this Assignment, you will create a Student class and a Faculty class, and assign them as subclasses of the superclass UHPerson. The details of these classes are in the UML diagram below: UHPerson - name : String - id : int + setName(String) : void + getName(): String + setID(int) : void + getID(): int + toString(): String Faculty Student - facultyList : ArrayList<Faculty - rank: String -office Hours : String - studentList...

  • 1) Write SQL to return the first and last name of all actors with a first...

    1) Write SQL to return the first and last name of all actors with a first name of "ADAM" (use the ACTOR table) 2) Write SQL with the LIKE operator to return addresses that are in the "Dhaka" district and have street addresses that do not contain the character sequence "Loop". You can return all information from the ADDRESS table that matches this criteria. 3) Write SQL with the BETWEEN and ORDER BY clause to return the payments in descending...

  • Please help me answer the following questions regarding data relationship tables. Employee ID First Name Last...

    Please help me answer the following questions regarding data relationship tables. Employee ID First Name Last Name email Title Address Extension Department Department ID Hiring Date Department Phone # 0001 John Smith jsmith Accountant 1300 West st 5775 Accounting 2100 8/1998 407-366-5700 0002 Brian Miller badams Admin Assistant 1552 Palm dr 5367 Human resource 2300 4/1995 407-366-5300 0003 James Miller miller Inventory Manager 2713 Buck rd 5432 Production 2520 8/1998 407-366-5400 0004 John Jackson jackson_sam Sales Person 433 tree dr...

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