[英]Regular expression for java.util.regex.Pattern
I am trying to create a suitable regular expression to use java.util.regex.Pattern 我正在尝试创建合适的正则表达式以使用java.util.regex.Pattern
I am using the regular expression shown below to match Strings like so: feed_user_at_gmail_dot_com_testfile
我正在使用下面显示的正则表达式来匹配这样的字符串: 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
但是,我需要创建另一个模式来匹配这样的字符串: 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. 区别在于第二个String是第一个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. 时间戳版本后面附加_ts_
和DATE,如上所示。 All dots in the DATE are changed to _dot_
DATE中的所有点均更改为_dot_
Thanks, Sony 谢谢,索尼
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. 如果日期总是正好有两个点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.