English 中文(简体)
定期表达从来不相称。
原标题:Regular expression never matches
  • 时间:2011-10-09 00:30:27
  •  标签:
  • java
  • regex

我的记录中有以下条目:

09-22-11 12:35:09 1ms   INFO         ...erChangeSetListener:91           11  processing changeSet for class:4328,at version:1316720109100
09-22-11 12:35:09 779ms INFO         ...erChangeSetListener:91           11  processing changeSet for class:4334,at version:1316720109882
09-22-11 12:35:09 1ms   INFO         ...erChangeSetListener:91           11  processing changeSet for class:4328,at version:1316720109882
09-22-11 12:35:11 1s    WARNING      QueryServiceImpl:100                -   no existing index for class:4328
09-22-11 12:35:11       SEVERE       QueryRequest:107                    7   Aod query resulted in error:No index available for class:4328
09-22-11 12:35:11       SEVERE       AuthenticationTask:48               -   EndUserException: an error occurred when processing the query                                  Dump: /data1/amir/dev/devots/logs/dumps/22i123511.dump

:

 final String pattern = "^(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})"  //date
                        + "[.]*" //ignore for now
                        + "(SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST)" //severity
                        + "[.]*"; //ignore the rest for now

 final Pattern regex = Pattern.compile(pattern);
 final Matcher m = regex.matcher(currentLine);
 if (m.matches()) {
     for (int i = 1; i <= m.groupCount(); i++) {
         System.out.format("[%d] "%s"%n", i, m.group(i));
     }
 }

但是,我的同声永远不会恢复。 我不理解为什么。 我愿有力处理这些不同类型的条目。 通知最后的登录有与其相关的倾销档案。

最佳回答

这里的问题是:

                    + "[.]*" //ignore for now

<代码>*>>><>>> 仅与字面对应,其通常含义不是“任何非线性” 页: 1

问题回答

You can t do [.]*. .* will suffice. You want any character, not a dot.

http://regexpal.com/“rel=“nofollow”http://regexpal.com/。

首先是简单匹配,开始逐条增加复杂性。

此外,为了明确起见,考虑指定以下团体:

^(?<date>d{2}-d{2}-d{2} d{2}:d{2}:d{2}).*(?<type>SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST).*




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签