regexp to extract the last underscore and the following letter (last letter) from words
19 ビュー (過去 30 日間)
古いコメントを表示
Ioannis Vourvachakis
2021 年 11 月 15 日
コメント済み: Ioannis Vourvachakis
2021 年 11 月 15 日
I want to use regexp in order to extract only the last underscore and the last letter from the words below.
But if I have the words 'apple_c' and 'apple_man_man_h'
and I use regexp(words,'\_\w','split'),
then I get as a result 'apple' for both words, but it is wrong for me, because I want to extract onlythe last underscore and thr last letter, as I said.
The desired result for me is 'apple' and ''apple_man_man'.
How should i modify the command to achieve this?
Thank you
0 件のコメント
採用された回答
Mathieu NOE
2021 年 11 月 15 日
hello
I recognize I am not the regexp expert here , so I would suggest this alternative :
ind = findstr(words,'_');
word_out = words(1:ind(end)-1)
3 件のコメント
Stephen23
2021 年 11 月 15 日
The behavior if there is no underscore might also be relevant:
words = 'apple';
ind = findstr(words,'_')
word_out = words(1:ind(end)-1)
What is the desired output in this case?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で String Parsing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!