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:

  pattern p = pattern.compile ("\\ bword \\" ", Pattern. CASEX ANSIVIE);  

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 [0-9A-Za-z _]

For example, _ass will not match.

You also have the problem of the derivative derivative ... where the word says, "hole", "wipe", etc. < / P>


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -