We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Using regular expressions in processing.
Page Index Toggle Pages: 1
Using regular expressions in processing. (Read 789 times)
Using regular expressions in processing.
Oct 26th, 2005, 6:37pm
 
I was surprised to find little info on how to use regular expressions in Processing, so I wanted to post about the java core library for using them aka:

import java.util.regex.*;

This opens up a few regular expression options, including the all important: myString.replaceAll();

Hope this saves someone a few minutes! Cheers.
Re: Using regular expressions in processing.
Reply #1 - Oct 26th, 2005, 10:17pm
 
Magic. Top post! Regular expressions are invaluable when it comes to Strings. Found some information:

http://www.regular-expressions.info/java.html

And to get people going, here's a simple bit of RegEx usage that identifies if a string is a valid email address format:
Code:

import java.util.regex.*;
String notEmail = "blahAtblah.com";
String myEmail = "st3ed@hotmail.com";
String check4EmailRegEx = "^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$";
void setup(){
println(notEmail.matches(check4EmailRegEx));
println(myEmail.matches(check4EmailRegEx));
}
Re: Using regular expressions in processing.
Reply #2 - Oct 30th, 2005, 1:42am
 
also note that this isn't supported in java 1.1, for what it's worth. p5 requires java 1.3 for now, but 1.1-only support will be coming back...
Page Index Toggle Pages: 1