Extract info using regular expression matching

Hello together,
I was trying to do some regurlare expression, I am getting correct output which i was expecting. can you please help me
myinp = {['getval' ('MYINFO\ECE1') '==19 & (getval(' 'MYDataCode\CSE' ') >= 4) & (getval(' 'MYCHANGE\DEPT' ') < 6'] };
[a,b]=regexp(myinp,'([^"])','tokens');
%expected output should be like
a{1,1} = getval('MYINFO\ECE1')
a{1,2} = getval('MYDataCode\CSE')
a{1,3} = getval('MYCHANGE\DEPT')

3 Kommentare

myinp = {['getval' ('MYINFO\ECE1') '==19 & (getval(' 'MYDataCode\CSE' ') >= 4) & (getval(' 'MYCHANGE\DEPT' ') < 6'] }
myinp = 1×1 cell array
{'getvalMYINFO\ECE1==19 & (getval(MYDataCode\CSE) >= 4) & (getval(MYCHANGE\DEPT) < 6'}
There are no quotes anywhere in this cellstr. Or is the actual input different from what you show us here?
this is my input
myinp = {['getval(' '''MYINFO\ECE1''' ')' '==19 & (getval(' '''MYDataCode\CSE''' ') >= 4) & (getval(' '''MYCHANGE\DEPT''' ') < 6)'] }
myinp = 1×1 cell array
{'getval('MYINFO\ECE1')==19 & (getval('MYDataCode\CSE') >= 4) & (getval('MYCHANGE\DEPT') < 6)'}
Stephen23
Stephen23 am 24 Mär. 2022
Your text does not have any double quote characters, that regular expression will match everything.
What is the purpose of the superfluous scalar cell array?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Rik
Rik am 24 Mär. 2022
Maybe this is what you need?
myinp = {['getval(' '''MYINFO\ECE1''' ')' '==19 & (getval(' '''MYDataCode\CSE''' ') >= 4) & (getval(' '''MYCHANGE\DEPT''' ') < 6)'] };
[a,b]=regexp(myinp{1},'getval\(''([^'']*)''\)','match')
a = 1×3 cell array
{'getval('MYINFO\ECE1')'} {'getval('MYDataCode\CSE')'} {'getval('MYCHANGE\DEPT')'}
b = 1×3
1 30 64

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 24 Mär. 2022

Beantwortet:

Rik
am 24 Mär. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by