Replacing commas with whitespaces using regexprep
1 view (last 30 days)
Show older comments
Raymond Wollenberg
on 18 Jun 2019
Commented: Raymond Wollenberg
on 19 Jun 2019
Hello,
i am new to Matlab and really struggling with the regexprep function. I try to replace commas in brackets with whitespaces, so i can use the split function, without splitting my data in brackets.
Task:
str= '(asdf,(50,51,52),jklö)'
str_desired='(asdf,(50 51 52),jklö)'
I already found this:
exp='(?<=\()[^)]*(?=\))'
rep=' '
newstr=regexprep(str,exp,rep)= '( ),jklö)'+
But its not quite doing what i want, and i cant figure out how to place the hexadecimalvalue '\x2C' for comma.
Thank you very much!
0 Comments
Accepted Answer
Stephen23
on 18 Jun 2019
>> str = '(asdf,(50,51,52),jkl)';
>> regexprep(str,'(\d+),(\d+),(\d+)','$1 $2 $3')
ans = (asdf,(50 51 52),jkl)
If you are already using regexprep I don't see the point in using strsplit as well, you might as well just use regexp to split the string up.
6 Comments
More Answers (0)
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!