Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
I really want to break the first group before _feed starts. So, the following works



Destiny's powerful hand has made the bed of my future. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 521 times.
Similar Threads
Loop for console input....
XML DOM & children nodes
Scanner hasNext() and indexoutofboundsexception
Pattern Matching
Java Regular Expressions
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:27:49.