regex - Matlab - how to replace all the special characters in a vector? -


is possible replace special characters in matlab vector through regular expression?

thank you

*edit: *

thank responses. i'm trying achieve following. have text file contains few paragraphs novel. have read file vector.

filetext = ['token1,' 'token_2' 'token%!3'] etc.

in case , _ % ! special characters , replace them blanks (''). can achieved through regular expressions? can javascript, can't work in matlab.

thank you

if "special characters" mean less-frequently used unicode characters ¥, , or ¼, can use either function regexprep or set comparison functions ismember (and can convert character string equivalent integer code first using function double if needed). here couple examples standard english alphabet characters (lower , upper case) removed string:

str = ['abcdefabcdefÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐ'];   %# sample string str = regexprep(str,'[^a-za-z]','');      %# remove characters using regexprep str(~ismember(str,['a':'z' 'a':'z'])) = '';  %# remove characters using ismember                                              %#   (as suggested andrew) str(~ismember(double(str),[65:90 97:122])) = '';  %# remove characters based on                                                   %#   integer code 

all of options above produce same result:

str =  abcdefabcdef 


edit:

in response specific example in updated question, here's how can use regexprep replace characters aren't a-z, a-z, or 0-9 blanks:

str = regexprep(str,'[^a-za-z0-9]',''); 

this may easier trying write regex match each individual "special" character, since there potentially many of them. however, if certain special characters _, %, , !, should achieve same above:

str = regexprep(str,'[_%!]',''); 

also, mentioned in comment amro, use function isstrprop replace non-alphanumeric characters blanks so:

str(~isstrprop(str,'alphanum')) = ''; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -