How to use regexp( ) In MATLAB
The regexp() function is used for matching the regular expression. It is case-sensitive.
Syntax:
startIndex = regexp(str, expression)
[startIndex, endIndex] = regexp(str, expression)
out = regexp(str, expression, outkey)
- startIndex = regexp(str, expression) is used to return the starting index of each substring of str that matches the character patterns specified by the regular expression. If there are no matches, startIndex is an empty array.
- [startIndex,endIndex] = regexp(str,expression) is used to return the starting and ending indices of all matches.
- regexp(str, expression, outkey) is used to return the output specified by the outkey. For example, if outkey is ‘match’, then this function returns the substrings that match the expression rather than their starting indices.
Example:
Matlab
% MATLAB code for regexp with strjoin() % Initializing a cell array A = { 'gfg' ; 'gfg1.23GFG' ; '5gfg10' }; b=regexp(A, '\d+(\.)?(\d+)?' , 'match' ) out=strjoin([b{:}], '' ) |
Output:
How to extract numbers from cell array in MATLAB?
In this article, we are going to discuss the extraction of numbers from the cell array with the help of regexp(), str2double(), cat(), and isletter() functions.