A data analyst is working with a customer contact table where the phone_number column contains data in multiple formats, including (555) 123-4567, 555-123-4567, and 555.123.4567. The goal is to standardize all entries into a NNNNNNNNNN format by removing all non-numeric characters. Which of the following data transformation techniques is MOST effective for this task?
Use a regular expression to find and replace all non-digit characters with an empty string.
Convert the phone_number column's data type from string to integer to automatically discard non-numeric characters.
Apply the TRIM function to remove the unwanted parentheses and hyphens from each entry.
Apply a series of nested REPLACE functions to remove each specific non-numeric character (e.g., '(', ')', '-', '.').
The correct answer is to use a regular expression (RegEx). A regular expression is the most effective and scalable method for this task because it allows for pattern-based searching and replacement. A single RegEx pattern, such as [^0-9] or \D, can identify all characters that are not digits in one operation, regardless of what the specific characters are.
Applying nested REPLACE functions is incorrect because it is inefficient and not robust. While it could work for the specific examples given, it would fail if new, unanticipated non-numeric characters (like spaces or other symbols) were present in the data. The analyst would need to add a new nested REPLACE for every possible character, making the query complex and hard to maintain.
Using the TRIM function is incorrect. The TRIM function is designed to remove characters or whitespace from the beginning or end of a string, not from the middle. It would not be able to remove the internal characters like ) or - in (555) 123-4567.
Converting the column's data type directly to an integer is incorrect because it will cause an error. Most database systems cannot cast a string that contains non-numeric characters (like parentheses, spaces, or hyphens) to a numeric data type and will raise a conversion error. The non-numeric characters must be removed before attempting any data type conversion.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What are regular expressions (RegEx) and how do they work?
Open an interactive chat with Bash
Why is using nested REPLACE functions less efficient than a regular expression?
Open an interactive chat with Bash
Can the TRIM function remove unwanted characters from anywhere in a string?
Open an interactive chat with Bash
CompTIA Data+ DA0-002 (V2)
Data Acquisition and Preparation
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .