Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use regex instead of contains() #5

Open
DavidRobertKeller opened this issue Jun 1, 2022 · 1 comment
Open

use regex instead of contains() #5

DavidRobertKeller opened this issue Jun 1, 2022 · 1 comment

Comments

@DavidRobertKeller
Copy link

Your java lib is really nice ! But you use "contains()" so to can't make difference between $rabbit and $rabbitYellow during replacement. @see stackoverflow.com/questions/42904361/… So you can update source with : Pattern.compile("(?<!\S)" + Pattern.quote(bookmark) + "(?!\S)");

best !
David

@DavidRobertKeller
Copy link
Author

DavidRobertKeller commented Jun 1, 2022

For example :

    public static boolean containsWord(String text, String bookmark) {
    	boolean contains = false;
		
    	if (text.contains(bookmark)) {
    		final Pattern pattern = Pattern.compile(Pattern.quote(bookmark) + "([^A-Za-z0-9]|$)");
    		final Matcher matcher = pattern.matcher(text);
    		while (matcher.find()) {
    			contains = true;
    			break;
    		}
    	}
    	
    	return contains;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant