Regular Expression to extract bigram
Show older comments
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 Comments
Walter Roberson
on 26 Sep 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 ?
arun
on 26 Sep 2013
Accepted Answer
More Answers (1)
Andrei Bobrov
on 26 Sep 2013
z=regexp(string,'\w*','match')
strcat(z(1:end-1),{' '},z(2:end))
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!