Reputation: 13314
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?
Upvotes: 0
Views: 1205
Reputation: 1878
Try the following:
.match(/Alert Message:/g)
This is a lot more general, it might trigger false alarms.
Upvotes: 0
Reputation: 552
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'.
Upvotes: 1