Regex match alert message

These may appear multiple times in a large string. Javascript Regex..

Trying to match both these cases - (the bolded text): First, ends with ), second ends with the 1st colon.

sometext sometext Alert Message: \\SERVERNAME: TFTP service is down - no heartbeat. (\\SERVERNAME)

and this:

IP Address: 1.1.1.1 : Alert Message: device name is unreachable : Event Class: /Status/Ping : Site:

This works for 2nd , but not for 1st

.match(/Alert Message:.*? :/g)

What rx will match both cases?

Answers


You can use a pipe '|' to indicate an 'or' in a regular expression. Also you can use .*? to skim over unimportant parts of the text to look for sections that are important. Here is an example of both in effect: http://jsfiddle.net/985Kg/

var regex = new RegExp('(Alert Message.*?TFTP service is down - no heartbeat.|Alert Message: device name is unreachable)');

alert(regex.test('Alert Message: \\SERVERNAME: TFTP service is down - no heartbeat. (\\SERVERNAME)')); // alerts 'true'.

Try the following:

.match(/Alert Message:/g)

This is a lot more general, it might trigger false alarms.


Need Your Help

Always get latest video in YouTube playlist

youtube-api youtube-javascript-api youtube-iframe-api

I would like to always show the latest video from a playlist. So, only show one video on the page, but always the most recent of a playlist. When a user has uploaded a new video on YouTube, that la...

Binary representation of an enum in protobuf-net

c# wcf serialization enums protobuf-net

Currently we are using a WCF Service with NetTcpBinding. We do have dataobjects which have an enum as property. We already have figured out, that out of the box these values are serialized as string