Bird
0
0

How can you use MATLAB regexp to split the string 'one,two;three four' into words separated by commas, semicolons, or spaces?

hard📝 Application Q9 of 15
MATLAB - String Handling
How can you use MATLAB regexp to split the string 'one,two;three four' into words separated by commas, semicolons, or spaces?
Aregexp(str, '[,; ]+', 'match')
Bregexp(str, '\\w+', 'split')
Cregexp(str, '[,; ]', 'split')
Dregexp(str, '[,; ]', 'tokens')
Step-by-Step Solution
Solution:
  1. Step 1: Identify delimiters

    Commas, semicolons, and spaces are delimiters: [,; ]
  2. Step 2: Use 'split' option with regexp

    regexp with 'split' splits string at delimiters, returning words.
  3. Final Answer:

    regexp(str, '[,; ]', 'split') -> Option C
  4. Quick Check:

    Use 'split' with delimiter pattern to split string [OK]
Quick Trick: Use 'split' with delimiter pattern to separate words [OK]
Common Mistakes:
  • Using 'match' returns delimiters, not words
  • Using 'tokens' without groups
  • Wrong pattern for splitting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes