I have a text that contains words that are enclosed by 2 spaces at the beginning and another 2 at the end like this:
"my_text_is__separated__like_this__example__"
so i want to retrieve 'separated' and 'example'.
I implemented it this way:
String pattern = "\\s{2}(\\w+)\\s{2}";
String t = getText();
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(t);
StringBuilder b = new StringBuilder();
while (m.find()) {
b.append(m.group(1) + "xxx\n");
}
Log.d("hmmmmm", b.toString());
but it doesn't work(m.find() is false).
edit: here's my text:
حَدَّثَنَا الْحُمَيْدِيُّ عَبْدُ اللَّهِ بْنُ الزُّبَيْرِ قَالَ حَدَّثَنَا سُفْيَانُ قَالَ حَدَّثَنَا يَحْيَى بْنُ سَعِيدٍ الْأَنْصَارِيُّ قَالَ أَخْبَرَنِي مُحَمَّدُ بْنُ إِبْرَاهِيمَ التَّيْمِيُّ أَنَّهُ سَمِعَ عَلْقَمَةَ بْنَ وَقَّاصٍ اللَّيْثِيَّ يَقُولُ سَمِعْتُ عُمَرَ بْنَ الْخَطَّابِ رَضِيَ اللَّهُ عَنْهُ عَلَى الْمِنْبَرِ قَالَ سَمِعْتُ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ يَقُولُ إِنَّمَا الْأَعْمَالُ بِالنِّيَّاتِ وَإِنَّمَا لِكُلِّ امْرِئٍ مَا نَوَى فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى دُنْيَا يُصِيبُهَا أَوْ إِلَى امْرَأَةٍ يَنْكِحُهَا فَهِجْرَتُهُ إِلَى مَا هَاجَرَ إِلَيْهِ.
'سُفْيَانُ' and 'بِالنِّيَّاتِ' for example should be among the outputs
note: in the example, I replaced the spaces with (_) so it becomes more visible.
note: my text is in Arabic.
edit: turns out it was not separated with double spaces, see the answer below.