Created
July 18, 2017 16:14
-
-
Save nuryslyrt/a349fb3a7b0713d800aa56f684ec3bc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class AnchorTagValidator{ | |
private Pattern pattern; | |
private Matcher matcher; | |
private static final String HTML_TAG_PATTERN = "<a(?=\s|>)(?!(?:[^>=]|=(['"])(?:(?!\1).)*\1)*?\shref=['"])[^>]*>.*?<\/a>"; | |
public AnchorTagValidator(){ | |
pattern = Pattern.compile(HTML_TAG_PATTERN); | |
} | |
public boolean validate(final String tag){ | |
matcher = pattern.matcher(tag); | |
return matcher.matches(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment