When I put \ b in pattern.compiler
it returns matcher.find
as false, because it can not find a pattern just because of \ b.
Following the code I use:
final Pattern py = Pattern.compile("\b(print|True|False|int|str|float|bool)\b)");
edittext.addTextChangedListener(new TextWatcher() {
Matcher m;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable e) {
m = py.matcher(e);
while (m.find()) {
e.setSpan(new ForegroundColorSpan(Color.WHITE),m.start() ,m.end() ,0);
}
}
});
But if I take the \ b works but not the way I want it.