How to use regexprep() In MATLAB

The regexprep() function is used to replace text using regular expressions.

Syntax: 

regexprep(str, expression, replace)

Example:

Matlab




% MATLAB code for regexprep method
% for string space removal
% Initializing a string
String = 'G e e k s f o r G e e k s';
 
% Replacing space with null using the
% regexprep() function over the above string
New_String = regexprep(String, '\s+', '')


 
 

Output:

 

New_String = w3wiki

How to remove space in a string in MATLAB?

In this article, we are going to discuss how to remove space from a string in MATLAB with the help of isspace(), find(), strrep(), and regexprep() functions.

Similar Reads

Using isspace()

The isspace() function is used to identify elements that are ASCII white spaces. isspace(‘string’) is used to find the white spaces present in the specified ‘string’....

Using strrep()

...

Using regexprep()

...

Using deblank()

...

Using strtrim()

...

Using erase()

The regexprep() function is used to replace text using regular expressions....

Using relational operator

...

Contact Us