Using the Match Filter

Implement the acceptMatch method in your Match Filter to add additional conditions to RegEx pattern matches. When a potential match is found acceptMatch is triggered, with the match start and end index (along with the full text being searched) passed in as parameters.

Listing 5-15 shows a MatchFilter implementation that cancels any match immediately preceded by an exclamation mark.

LISTING 5-15: Using a Linkify Match Filter class MyMatchFilter implements MatchFilter {

public boolean acceptMatch(CharSequence s, int start, int end) { return (start == 0 || s.charAt(start-l) != '!');

Available for download on Wrox.com

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment