質問

I am using ELMAH to log exceptions that are caught during application execution.

On of the most frequent error messages is like so:

The file '/page/default.aspx' does not exist.

The file. '/error/404/default.aspx' does not exist.

The file. '/another/test/page/default.aspx' does not exist.

Since I can filter certain exceptions from ELMAH by setting regular expressions in web.config, I am trying to write a regular expression to catch messages like this.

This is what I have so far, but gut instinct tells me it's going to fail potentially.

The file '((\/\w)+|(\w))+\.aspx' does not exist.

Could anyone offer any advise on what I can do to make this expression more stable?

It only needs to handle *.aspx pages.

役に立ちましたか?

解決

You could make it less specific. The following expression would also do the trick perfectly:

The file '.+\.aspx' does not exist\.

Note the backslash escaping the period at the end. The . character is special, it usually means "match any character other than a linebreak". It would work without the backslash, but then it would match any single character after exist.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top