We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Regex script logic to parse

dvelloriy
Kilo Sage

Hi Team,

I have below script which i am using to parse host name and group name from a column in staging table.

This is working fine in some cases where alert tags have defined position (0 for host names and 2 for support group).

There are many other alerts where the positions get swapped. So i need to convert below script to use regex logic to identify Hostname and Support group values.

Please advise.

 

var str = source.tags;
//'Hostname:NAP01-OND02,Vitality:V0,Support Team:Real Time Applications,Application Name:EDS';

var arr = str.split(',');

var ci = arr[0].split(':')[1];
var suppG = arr[2].split(':')[1];

 

 

6 REPLIES 6

Hello, can you please share the code?

Sure, Here it is:

// Regex to match the hostname
var string = "Hostname:NAP01-OND02,Vitality:V0,Support Team:Real Time Applications,Application Name:EDS";
var regex = /Hostname:([^,]+)/;
var match = string.match(regex);
var hostname = match ? match[1] : null;

gs.log('Extracted Hostname: ' + hostname);