0

I am trying to create a suitable regular expression to use java.util.regex.Pattern

I am using the regular expression shown below to match Strings like so: feed_user_at_gmail_dot_com_testfile

final static Pattern PATTERN1 = Pattern.compile("feed_(.*)_([^_]*)");

This works as expected. But, I need to create another Pattern to match Strings like so: feed_user_at_gmail_dot_com_testfile_ts_20120413_dot_175531_dot_463

The difference is that the second String is a time stamped version of the first String. These two Strings are examples of file names in my database and I need to identify them both separately. The time stamped version is appended with _ts_ followed by DATE as shown above. All dots in the DATE are changed to _dot_

Thanks, Sony

1 Answer 1

1

How about this:

"feed_(.*)_([^_]*)_ts_[1-9]+(_dot_[1-9]+)*"

Or better yet,

"feed_(.*)_([^_]*)_ts_[1-9]+(_dot_[1-9]+){2}"

if dates always have exactly two dots.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.