Regular Expression to extract bigram
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
string = 'ab bc cd ef gh ij kl'
what will be the regular expression to extract bigram from the given string
I am writing the code
regexp(string,'\w* \w*','match');
the o/p is coming as: 'ab bc' 'cd' 'ef' 'gh' 'ij' 'kl'
while the output i am expecting as:
- 'ab bc'
- 'bc cd'
- 'cd ef'
- 'ef gh'
- 'gh ij'
- 'ij kl'
2 Commenti
Walter Roberson
il 26 Set 2013
I believe the term is "bi-gram".
If the string was
'abc defg'
would you want the result to be
ab bc c<space> <space>d de ef fg
or
ab de
or
ab bc de ef fg
?
Or does it only need to work on letter pairs ?
Risposta accettata
Azzi Abdelmalek
il 26 Set 2013
Modificato: Azzi Abdelmalek
il 26 Set 2013
EDIT
Do you want?
string = 'ab bc cd ef gh ij kl'
regexp(string,'\s+','split');
3 Commenti
Azzi Abdelmalek
il 26 Set 2013
string = 'ab bc cd ef gh ij kl'
out=regexp(string,'\s+','split');
cellfun(@(x,y) [x ' ' y],out(1:end-1)', out(2:end)','un',0)
Più risposte (1)
Andrei Bobrov
il 26 Set 2013
z=regexp(string,'\w*','match')
strcat(z(1:end-1),{' '},z(2:end))
0 Commenti
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!