Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Using regular expressions in Java Pattern: java.util.regex.Pattern  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Say, I have a String like so: ts_20120413_dot_175531_dot_463_feed_user_at_gmail_dot_com_filename

This is a file name in the database which is prefixed with a timestamp, all dots and @ are replaced with _dot_ and _at_. I need to create a Pattern that matches Strings of the above type which can be split into three groups like so:

group1: ts_20120413_dot_175531_dot_463
group 2: user_at_gmail_dot_com
group 3: filename

I tried:



The above code snippet throws the error: Invalid file name.
The expected output is:
Group 1 is: ts_20120413_dot_175531_dot_463
Group 2 is: user_at_gmail_dot_com
Group 3 is: filename

I can't figure out how to fix the error

- Sony
 
author
Posts: 23811
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sony vijay wrote:Hi,

Say, I have a String like so: ts_20120413_dot_175531_dot_463_feed_user_at_gmail_dot_com_filename

This is a file name in the database which is prefixed with a timestamp, all dots and @ are replaced with _dot_ and _at_. I need to create a Pattern that matches Strings of the above type which can be split into three groups like so:

group1: ts_20120413_dot_175531_dot_463
group 2: user_at_gmail_dot_com
group 3: filename

I tried:



The above code snippet throws the error: Invalid file name.
The expected output is:
Group 1 is: ts_20120413_dot_175531_dot_463
Group 2 is: user_at_gmail_dot_com
Group 3 is: filename

I can't figure out how to fix the error



Hint: are there numbers that can't be matched with "[1-9]+" ??

Henry
 
sony vijay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really want to break the first group before _feed starts. So, the following works



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!