String matching in java -
I am currently struggling to find partial matches with my "Dirty Words" filter.
Example: If I
replace the personal string string with the word (string word, string input) {/ p> for this method Pattern Legacy Pattern = Pattern.compile (word, Pattern.CASE_INSENSITIVE); Matcher matcher = Legacy Pattern.matcher (input); Stringbilder return string = new stringbilder (); Int index = 0; While (matcher.find ()) {returnString.append (input.substring (index, matcher.start ())); For (int i = 0; i & lt; word.length () - 1; i ++) {returnString.append ('*'); } ReturnString.append (word.substring (word.length () - 1)); Index = matcher.end (); } If (index
me p * sing p * sp ** sed ** s
when I really want "passing pass passed" Anyone can know how to avoid partial matching with this method? Any help will be great thanks!
Will tell you in the right direction. You want to use the word limit in your pattern: Note, though it is still problematic ( As it is always that filth is filtered out). A "non-word character" defining the limit is not included in For example, You also have the problem of the derivative derivative ... where the word says, "hole", "wipe", etc. < / P>
pattern p = pattern.compile ("\\ bword \\" ", Pattern. CASEX ANSIVIE);
[0-9A-Za-z _]
_ass
will not match.
Comments
Post a Comment