[DialogJIG] J2SE 1.4 to include regular expressions

  • From: Andrew_Tetlaw@xxxxxxxxxxxxx
  • To: dialogjig@xxxxxxxxxxxxx
  • Date: Tue, 30 Oct 2001 09:10:54 +1000

This is pretty cool:

"Once you've mapped the input file to a CharBuffer, you can do pattern
matching on the file contents. Think of running grep or wc on the file to
do regular expression matching or word counting, respectively. That's where
the java.util.regex package comes into play and the Pattern and Matcher
classes get used."

For those that don't know Regular expressions are  very groovy. They're
supported by a lot of languages like Perl, JavaScript, PHP and so on and
are a way to to pattern matching in strings very efficiently. For example
if I had a string called string and I wanted to get rid of all non alpha
numerics I could do this in Perl:

string =~ s/[^a-zA-Z0-9]//g

the s/// is the substitution syntax: s/<string to match>/<string to replace
it with>/

the [] indicates a set, in the above exmaple that means any character match
the ranges a-z , A-Z or 0-9
the ^ chanracter means the inverse of the set.
the g at the end means globally, that is: every match, not just the first

So basically any character not matching the set repalce with nothing.

Now I'm no expert (I had to look up the example in  my Perl book) but I
know thatan expert can create quite powerful regular expressions to do
complex string matching/replacing and so on.

Andrew Tetlaw
Dialog Information Technology

Dialog JIG! Mailing List:

To subscribe/unsubscribe send an email to dialogjig-request@xxxxxxxxxxxxx with 
'subscribe' or 'unsubscribe' in the Subject field.

List Archive: http://www.freelists.org/archives/dialogjig/
FAQ: email dialogjig-request@xxxxxxxxxxxxx with 'faq' in the subject field

Other related posts:

  • » [DialogJIG] J2SE 1.4 to include regular expressions