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

  • Write a single SELECT statement to project your first name, last name, student ID and a...

    Write a single SELECT statement to project your first name, last name, student ID and a short description of yourself as four string literals. i am really confused because if there is no tables then how do we write a statement???

  • Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...

    Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class. HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...

  • 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...

  • 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...

  • 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...

  • 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...

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