java - Regex to find last letter in word for any String -


i have small problem regular expressions ( regex ).

i want remove "t" @ end of each word in string.
code using display words ending "t".

public static void main (string []args){     string name = "phylaurheimsmet hello tttttyyuolktttb fedqs jhgjt";     p = pattern.compile("([a-z0-9]+)?[t]");     m = p.matcher(s);      while (m.find()) {         system.out.println(m.group());     } } 

thank help.

i try remove "t" @ end of each word

string.replaceall("t(?!\\s)", ""); 

this match t's present @ end of each word.

or

string.replaceall("t(?=\\s|$)", ""); 

this match t's if it's follwed space or end of line anchor.

to case-insensitive replacement.

string.replaceall("(?i)t(?!\\s)", ""); 

demo


Comments