// processing regular expressions import java.util.regex.*; void setup() { // String s = "The cat sat on the mat."; // String a = s.replaceAll("cat", "hello"); // println("a: " + a); // String b = s.replaceAll(".at", "hello"); // println("b: " + b); // String c = s.replaceAll("[cm]at", "hello"); // println("c: " + c); // String d = s.replaceAll("\\.", ""); // println("d: " + d); // String e = s.replaceAll("[T|t]he", "My"); // println("e: " + e); ////////////////////////////////////////// // phone call matcher //String z = "Give me a call on 206-543-4218"; //String lines[] = loadStrings("/Users/rtwomey/Documents/script/script.txt"); String lines[] = loadStrings("/Users/rtwomey/Documents/script/reading reference.txt"); println("there are " + lines.length + " lines"); for (int i=0; i < lines.length; i++) { String z = lines[i]; Pattern p = Pattern.compile("call"); Matcher m = p.matcher(z); boolean found = m.find(); // println(found); if(found) println(i+": "+m.group()+" "+z); // extract phone info Pattern q = Pattern.compile("[0-9]{3}\\-[0-9]{3}\\-[0-9]{4}"); Matcher n = q.matcher(z); found = n.find(); if(found) { String tel = n.group(); println(tel); String tl[] = split(tel, "-"); tel = join(tl, ""); println(tel); } } }