The following class demonstrates basic use of Java's Pattern and Matcher class by adding the rel attribute 'nofollow' to the anchor tags of several links.
*Note, this is for educational purposes only. Pattern, Matcher and Regex are NOT ideal for manipulating HTML in Java.
NoFollow.java
//Adds NoFollow rel attribute to links //Demonstrates StringBuilder, Pattern, Matcher, Regex import java.util.regex.*; public class NoFollow{ private StringBuilder[] links = new StringBuilder[10]; //Create some test links public NoFollow(){ for(int i=0; i<10; i++){ links[i] = new StringBuilder("Test "+i+""); } } public static void main(String[] args){ NoFollow nf = new NoFollow(); StringBuilder[] links = nf.getLinks(); //Add 'nofollow' rel attribute for(int i=0; i





