regexprep( filecontent, 'R.*$', '', 'dotexceptnewline', 'lineanchors');

1 Comment

Stephen23
Stephen23 on 21 Jul 2016
Edited: Stephen23 on 25 Jul 2016
@bharath gopireddy: you can use my FEX submission makeregexp to experiment with regular expressions. You can download it here:
It creates a figure that lets you interactively develop and change a regular expression, and shows you all regexp outputs as you type.

Sign in to comment.

 Accepted Answer

bharath - see regexp and regexprep. It appears that this line of code is trying to replace text using regexprep, looking for all occurrences of words or phrases (?) beginning with R and replacing with a blank string up to the end of a line (see details on dotexceptnewline and lineanchors).
For example, if
filecontents = sprintf('Ralph\nRoger\nGeoff\nStaRWars\nCaR\nSpaRtan\nSpartan')
filecontents =
Ralph
Roger
Geoff
StaRWars
CaR
SpaRtan
Spartan
then
regexprep( filecontents, 'R.*$', '', 'dotexceptnewline', 'lineanchors')
ans =
<--- empty
<--- empty
Geoff
Sta
Ca
Spa
Spartan
Try some examples on your own, removing the dotexceptnewline and lineanchors to see their effect.

More Answers (0)

Asked:

on 20 Jul 2016

Edited:

on 25 Jul 2016

Community Treasure Hunt

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

Start Hunting!