gusucode.com > bigdata 工具箱 matlab源码程序 > bigdata/@tall/regexprep.m

    function out = regexprep(in, expr, rep, varargin)
%REGEXPREP Replace string using regular expression.
%   S = REGEXPREP(STRING,EXPRESSION,REPLACE)
%   S = REGEXPREP(STRING,EXPRESSION,REPLACE,OPTION)
%
%   See also TALL/STRING.

%   Copyright 2016 The MathWorks, Inc.

narginchk(3,4);

% First input must be a tall string.
if ~istall(in)
    error(message('MATLAB:bigdata:array:ArgMustBeTall', 1, upper(mfilename)));
end
in = tall.validateType(in, mfilename, {'string','cellstr'}, 1);

% Remaining arguments must not be tall and EXPR and REP must be valid
% text inputs (char row, string, cellstr).
checkNotTall(upper(mfilename), 1, expr, rep, varargin{:});
expr = iCheckAndMaybeWrapChar(expr, 'PATTERN');
rep = iCheckAndMaybeWrapChar(rep, 'REPLACE');

% Element-wise in first input, with all others bound in.
out = elementfun(@(x) regexprep(x,expr,rep,varargin{:}), in);
% Output is same size and type as input (cellstr or string)
out.Adaptor = in.Adaptor;

end

function x = iCheckAndMaybeWrapChar(x, name)
% Wrap char arrays in cells to ensure they are treated as scalar
if ischar(x)
    if ~isrow(x) && ~isequal(size(x),[0 0])
        error(message('MATLAB:REGEXP:invalidInputs',name));
    end
    x = {x};
elseif ~iscellstr(x) && ~isstring(x)
    % Not a valid text input
    error(message('MATLAB:REGEXP:invalidInputs',name));
end
end