• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
sony vijay
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
 
Henry Wong
author
Sheriff
Posts: 23295
125
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!