2016-08-22 23 views
0

Here is the Console log:<a href..> html tag

10:16:02 2016-08-10 10:16:01.087 [INFO] (1): DEVICE_DAILY_SKIPS_SUBSCRIBER=60 
10:16:02 2016-08-10 10:16:01.087 [INFO] (1): DEVICE_DAILY_SKIPS_REGISTERED=48 
10:16:02 2016-08-10 10:16:01.088 [INFO] (1): DEVICE_HOURLY_STATION_SKIPS_SUBSCRIBER=6 
10:16:02 2016-08-10 10:16:01.284 [INFO] (1): Post results =true 
10:16:02 2016-08-10 10:16:01.290 [INFO] (1): Calling Api...... 
10:16:05 2016-08-10 10:16:04.289 [INFO] (1): Run URL = <a href="https://sv5.ad.mobile.com/index.php?/runs/view/2435" target="_blank">Run = R2435</a> 
10:16:05 2016-08-10 10:16:04.293 [INFO] (1): [CONFIGURATION BeforeSuite] AbstractBaseTest#setUpBeforeSuite 
10:16:05 2016-08-10 10:16:04.307 [INFO] (1): SHORT_TIMEOUT: 1000 

Above is the Jenkins build console log and I am in the process of parsing it to find the desired URL along with the enclosing <a href.. html tag. For example in above log, I want to find this: <a href="https://sv5.ad.mobile.com/index.php?/runs/view/2435" target="_blank">Run = R2435</a> with the help of Regular Expressions.

Here is what I have tried:

<a href="https://sv5.ad.mobile.com/index.php?/runs/view/.*"> but does not seem to work. Also, is there a way to have a little compact regular expression for such kind of this search? How to find such URLs in the logs with the help of regex?

+0

You are aware of that the '?' is a special character in regular expressions? So are dots. –

答えて

1

Once you escape the .s and ?s, what you had already should mostly work. You need to also allow for other attributes like target="_blank":

<a href="https://sv5\.ad\.mobile\.com/index\.php\?/runs/view/[^"]*"[^>]*> 

[^"]* means "any number of characters that aren't double quotes", and [^>]* similarly means "any number of characters that aren't right angle brackets."

You might want to be even more flexible by allowing attributes to appear preceding the href too:

<a [^>]*href="https://sv5\.ad\.mobile\.com/index\.php\?/runs/view/[^"]*"[^>]*> 

As to whether it could be more compact, that depends on what you're trying to find. You only gave us one example, so it's pretty hard for us to speculate.

関連する問題