Win a copy of Pragmatic AI this week in the Artificial Intelligence 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
Sheriff
Posts: 23571
138
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



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!