Regular Expression to extract bigram
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2013년 9월 26일
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 ?
채택된 답변
Azzi Abdelmalek
2013년 9월 26일
편집: Azzi Abdelmalek
2013년 9월 26일
EDIT
Do you want?
string = 'ab bc cd ef gh ij kl'
regexp(string,'\s+','split');
댓글 수: 3
Azzi Abdelmalek
2013년 9월 26일
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)
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!