FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Integration
(Moderators: fry, REAS)
   understanding Java's regex implementation
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: understanding Java's regex implementation  (Read 750 times)
kevinP

Email
understanding Java's regex implementation
« on: Jun 12th, 2004, 7:13pm »

Hi,
 
I have:
Code:

// Java regex demo
 
import java.util.regex.*; // import regex package
 
class regexDemo extends BApplet {
 
  void draw()
  {  
    // For one-time matches
    boolean a = Pattern.matches("a*b", "babaabaaaaaa"); //  
    println("a: Find 'a*b' in 'babaabaaaaaa' - " + a);
    
    boolean b = Pattern.matches("a*b", "bbbbbbbb"); //  'a' zero or more times, followed by b...
    println("b: Find 'a*b' in 'bbbbbbbbb' - " + b);
  }
 
 
} // end of sketch class

 
And it returns false for both cases. But shouldn't the second match return 'true'? (Hmmm, actually shouldn't both return 'true'?)
 
-K
« Last Edit: Jun 12th, 2004, 7:16pm by kevinP »  

Kevin Pfeiffer
TomC

WWW
Re: understanding Java's regex implementation
« Reply #1 on: Jun 12th, 2004, 8:31pm »

No, I don't think so.  This matches method will return true only if the whole string matches the given regular expression.  It isn't searching for a substring.
 
 
kevinP

Email
Re: understanding Java's regex implementation
« Reply #2 on: Jun 12th, 2004, 10:35pm »

Ah, of course! (dumb of me)
 
I needed to validate some input and noticed that the tech notes include little on parsing/matching, so I'll try to post a little demo later maybe.
 
-K
 

Kevin Pfeiffer
Pages: 1 

« Previous topic | Next topic »