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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by