• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about Regex Parsing in Java

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool. Gald you got it!
 
reply
    Bookmark Topic Watch Topic
  • New Topic