How to find all letters before a character in a char variable

1 回表示 (過去 30 日間)
Boris Chan
Boris Chan 2019 年 12 月 1 日
コメント済み: Vladimir Sovkov 2019 年 12 月 1 日
I need to find a message hidden in a bunch of random characters. I have this secret message and I know that all the words are spaced inbetween the '#' character. I have been trying to use the regexp to find all the letters in between every '#'
secretMes = ';,.T234h467e#i`12n390@%f&^%o1@45r1%^m]\a131@t2i*/-o+/1n#i*895n#t$5&&h1/!i@$$s#f18945@i2/le#i98s#c`$%o%^n77*f(=i(*d@!e1*/n--t+/*i1/2a@@l' ...
,'D/44o#n$%7o76@@t#s&*&&9h998o()-w#t=-++h=!2i@@s#t%%^o#a$()-=n12//*8y//8-o++/n00/7e' ...
,'H@!0a-0009v$%%e#a#w%^o^&n*!@d!~*e12//*r+*/8f1-/u00l#t0/8h%^a34$n%^&k()-s[}}g;;i<>v1/8i1@@n4%g#e$@v8998e**98r7^^y))(o--=n;:e';
toFind = '\w+(\#)?'
decrypt = regexp(secretMes,toFind,'match');
unfortuantely it doesn't seem to be giving me the desitred results
Ti1fo4mato1i8t5hisfiliconfidenti2lD4n7ts9wth2stoan88on7H00eawonder8ut8anksgiv8ngev9yone
does anyone know how to achieve this?

回答 (2 件)

Vladimir Sovkov
Vladimir Sovkov 2019 年 12 月 1 日
split(secretMes,'#')
  2 件のコメント
Boris Chan
Boris Chan 2019 年 12 月 1 日
Hi thanks for the input,
But this doesn't parse the words and the numbers apart.
Vladimir Sovkov
Vladimir Sovkov 2019 年 12 月 1 日
S=split(secretMes,'#');
S0=S{1}(S{1}>='A' & S{1}<='Z' | S{1}>='a' & S{1}<='z');
for k=2:numel(S)
S0 = strcat(S0,'_', S{k}(S{k}>='A' & S{k}<='Z' | S{k}>='a' & S{k}<='z'));
end
S0

サインインしてコメントする。


Stephen23
Stephen23 2019 年 12 月 1 日
>> secretMes = [';,.T234h467e#i`12n390@%f&^%o1@45r1%^m]\a131@t2i*/-o+/1n#i*895n#t$5&&h1/!i@$$s#f18945@i2/le#i98s#c`$%o%^n77*f(=i(*d@!e1*/n--t+/*i1/2a@@l' ...
'D/44o#n$%7o76@@t#s&*&&9h998o()-w#t=-++h=!2i@@s#t%%^o#a$()-=n12//*8y//8-o++/n00/7e' ...
'H@!0a-0009v$%%e#a#w%^o^&n*!@d!~*e12//*r+*/8f1-/u00l#t0/8h%^a34$n%^&k()-s[}}g;;i<>v1/8i1@@n4%g#e$@v8998e**98r7^^y))(o--=n;:e'];
>> C = regexp(secretMes,'#','split');
And checking:
>> C{:}
ans = ;,.T234h467e
ans = i`12n390@%f&^%o1@45r1%^m]\a131@t2i*/-o+/1n
ans = i*895n
ans = t$5&&h1/!i@$$s
ans = f18945@i2/le
ans = i98s
ans = c`$%o%^n77*f(=i(*d@!e1*/n--t+/*i1/2a@@lD/44o
ans = n$%7o76@@t
ans = s&*&&9h998o()-w
ans = t=-++h=!2i@@s
ans = t%%^o
ans = a$()-=n12//*8y//8-o++/n00/7eH@!0a-0009v$%%e
ans = a
ans = w%^o^&n*!@d!~*e12//*r+*/8f1-/u00l
ans = t0/8h%^a34$n%^&k()-s[}}g;;i<>v1/8i1@@n4%g
ans = e$@v8998e**98r7^^y))(o--=n;:e

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by