如何使用正则表达式基于fullstops获取子字符串?我们只希望在完全停止后获取数据
Str = “i like cows. I also like camels”
// Regex Code here
Output : “I also like camels”
答案 0 :(得分:2)
不需要使用正则表达式。使用private Handler handler = new Handler(Looper.getMainLooper());
private int temperature = 0;
private TextView textView;
public Runnable runnable = new Runnable() {
@Override
public void run() {
if (textView != null) {
textView.setText(String.valueOf(temperature));
}
}
};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.text);
findViewById(R.id.btn_add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handler.removeCallbacksAndMessages(runnable);
handler.postDelayed(runnable, 1000);
if (temperature < 32) {
temperature++;
}
}
});
findViewById(R.id.btn_minus).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handler.removeCallbacksAndMessages(runnable);
handler.postDelayed(runnable, 1000);
if (temperature > 17) {
temperature--;
}
}
});
}
@Override
protected void onStop() {
handler.removeCallbacksAndMessages(runnable);
super.onStop();
}
方法。
split()
答案 1 :(得分:2)
您可以使用此方法:
str1 = 'i like cows. I also like camels'
print(str1.split('.')[1:][0].strip())
输出:
I also like camels
答案 2 :(得分:1)
尝试此拆分
String dataIWant = mydata.split(“。”)[1];
结果:我也喜欢骆驼
答案 3 :(得分:1)
使用split('。')并选择最后一个元素通常会更好,但对于 fun ,这是一个RegEx解决方案:
+
答案 4 :(得分:0)
此String: "abcdefg"
Code unit count : 11
Grapheme cluster count: 9
选择(?:[.]\s([A-Z].+))