Matching the first two words
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
wesso Dadoyan
el 8 de Jun. de 2015
Comentada: Guillaume
el 8 de Jun. de 2015
Hi,
I have two cell arrays A and B. A(1)= American Express Corporation B contains cells with the following string "AMERICAN EXPRESS CO" the two companies are the same but they won't match unless I ask to match the first two words (with case insensitive matching). How can I find the cells in B that matches A(1) based on the first two words only? Best, Wesso
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 8 de Jun. de 2015
A={'American Express Corporation','American1 Express Corporation','American2 Express Corporation'}
B={'AMERICAN EXPRESS CO','AMERICAN3 EXPRESS CO', 'AMERICAN1 EXPRESS CO' }
a=regexp(A,'\s+','split')
b=regexp(B,'\s+','split')
a1=upper(cellfun(@(x) [x{1},x{2}],a,'un',0))
b1=upper(cellfun(@(x) [x{1},x{2}],b,'un',0))
Now you can compare your companies
4 comentarios
Guillaume
el 8 de Jun. de 2015
regexp(str, '$[A-Za-z]+', 'match')
will return only the beginning of a string up to the first non-letter.
However, rather than making the string matching algorithm more and more complicated, I would rather focus my efforts in making sure the inputs were properly formatted in the first place.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!