Python
All Top Python Interview Questions#9
Sanitize Text Strings with Regex in Python
EasyInterview Question #9
Given a noisy customer search string like ' iPhone 15, Pro Max!! (256GB) ', write a Python regex function to remove all non-alphanumeric characters (except spaces) and collapse multiple whitespace into a single space.
Input Table: noisy_strings
1 rows preview| input_str |
|---|
| iPhone 15, Pro Max!! (256GB) |
Expected Output Structure1 rows
| sanitized_str |
|---|
| iPhone 15 Pro Max 256GB |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
Python 3.10 (Pandas)
Environment Ready
Starting the real Python + pandas runtime (one-time download)…