File Exchange

image thumbnail

strpat: a pedestrian, exactly matching pattern finder / replacer

version (2.83 KB) by us
STRPAT finds and replaces an exactly matching pattern in a character or numeric string

1 Download

Updated 22 Apr 2010

View Version History

View License

STRPAT searches for EXACTLY matching patterns
in a character or numeric string and replaces
the occurrences with another pattern.

a single or double precision pattern
may include NaNs

% examples

% - character strings

% note difference
% aa_XXX_aaa_aa

% X_a_aaa_X

% - numeric strings
% 1 2 3 NaN 5 6 7

% 3.1416 6.2832 9.4248 18.85

strpat(pi*(1:6),pi*(4:5),[nan inf -inf nan])
% 3.1416 6.2832 9.4248 NaN Inf -Inf NaN 18.85

% 3.1416 6.2832 9.4248 1 2 3 18.85

% - PATTERN including NaNs
% -10 Inf -10 NaN Inf Inf -10

see also
>> help strpat
or the screenshot for help on this self-explanatory function

Cite As

us (2020). strpat: a pedestrian, exactly matching pattern finder / replacer (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)


excellent. overcomes the short comings of regexprep

Carlos Adrian Vargas Aguilera

I downloaded it because I found it at 2nd place at "Most downloaded"!, and I found it very useful. I just would prefer a WARNING message instead of a DISPLAY, in order to be able to avoid it and just looking into the .n field at the second output, which, by the way, was very clever.

Thanks us for the submission.

Leandro Navarro

MATLAB Release Compatibility
Created with R12.1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!