// Uncolored, plain source file:  tst.java
// <p> // An example file explaining how to use // com.stevesoft.pat, com.stevesoft.pat.wrap, // and com.stevesoft.pat.apps // <p> // This software comes without express or implied warranty. // No claim is made about the suitability of this software for // any purpose and neither we nor SteveSoft shall be liable for // damages suffered by the user of this software. import com.stevesoft.pat.*;
public class tst { public static void main(String[] unused) { // Some crazy patterns... Regex r = null; r = new Regex("([a-d]).*?\\1"); r.search("foo d foo c foo b foo d foo d foo"); doOutput(r); r = new Regex("[\\dX]+"); r.search("match here => 9353X35"); doOutput(r); r = new Regex("foo(?=(bar))"); r.search("not foo but foobar only!"); doOutput(r); r = new Regex("\\bfoo\\b"); r.search("not foobar, nor barfoo, but foo and foo alone!"); doOutput(r); }
public static void doOutput(RegRes r) { System.out.println("before match => "+r.left()); System.out.println("match => "+r.stringMatched()); System.out.println("after match => "+r.right()); for(int i=1;i<=r.numSubs();i++) System.out.println(" ["+i+"] = "+r.stringMatched(i)); System.out.println(""); } }
/* The output: before match => foo match => d foo c foo b foo d after match => foo d foo [1] = d before match => match here => match => 9353X35 after match => before match => not foo but match => foo after match => bar only! [1] = bar before match => not foobar, nor barfoo, but match => foo after match => and foo alone! */