Performs regular expression replacement in a file or files
Updated 11 Sep 2013

View License

regexprepfile(filename,exp,repstr) performs a regular expression replacement using the pattern exp in the file filename with the string repstr. exp, repstr may also be cell arrays of strings of the same size, in which case the replacement is performed for each pair by performing a regexprep using corresponding elements of the inputs. Alternatively repstr may be a string and exp a cell array, in this case the single string repstr will replace all the patterns in exp.


regexprepfile replaces the string by creating a temporary copy of the file in which the replace is to be performed, replacing it in this file, and copying the file back to the original location for safety.


Note regexprepfile requires 'samesize.m' my file exchange contribution here:

Cite As

Richard Crozier (2024). regexprepfile (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Characters and Strings in Help Center and MATLAB Answers

Inspired by: samesize

Inspired: refactor_fcn_name

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

asthetic change to file description, no change to file