Programming issues for really using Java regex for Huntingtons problem

  • To get \s inside a Java string, you will need to write \\s.
  • The way the newline character and the . character of regex interact is arbitrary, so you will need to do something about this because the typical input file will have multiple lines. One possibility is to read in all the characters into a big string and then replace every \n newline character with a space. Another possibility is to read in the input one line at a time and build up the input in a StringBuilder (you can't use String because strings are immutable) and then change the String at the end.
  • Your professor solved this problem using the String matches() method, but remember that matches() matches the entire string. If you want to use partial matches, then you will need to use the java.util.regex Pattern and Matcher classes.

-- Main.sloan - 2012-02-12

Edit | Attach | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2012-02-12 - 20:27:00 - Main.sloan
Copyright 2016 The Board of Trustees
of the University of
Helping Women Faculty Advance
Funded by NSF