• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about Regex Parsing in Java  RSS feed

 
Shawn Smith
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm attempting to determine valid email address formation using regex and failing. I've tested the same regex against the C regcomp and regexex, and boost's c++ regex libraries with consistent (and correct results). The java code fails to match on anything though. Any insight into the differences in processing would be greatly appreciated.

The matching code:



The test code:


I'm expecting shawn@psu.edu and pit.barbecue@psu.edu to match.

Cheers,
Shawn
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.regular-expressions.info/email.html

And if that doesn't answer your question, I'm sure you can get plenty of help by googling for something like java email regex.

Also note that you probably don't want a regex that perfectly matches the RFC for email addresses, for reasons spelled out in the regular-expressions.info link, and if you choose to do so, it will be a horrendous regex.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note also that for POSIX character classes, Java uses \p{class}, not [:class:], which is spelled out in the docs for java.util.regex.Pattern, so \p{Alnum}, which of course becomes if you're using a Java String literal to specify the pattern.

Always worth reading the docs before posting to a forum.
 
Shawn Smith
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:Note also that for POSIX character classes, Java uses \p{class}, not [:class:], which is spelled out in the docs for java.util.regex.Pattern. Always worth reading before posting to a forum.


Thanks much. I actually had read it and just figured out that Properties was stealing my escape for the \p{class} which had me chasing my tail.

Thanks again for the feedback.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. Gald you got it!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!