Extract Numeric part from a particular string field

Vamsi Kambhamp2
Kilo Explorer

I wanted to extract numeric values from a given string in servicenow.
I wanted to implement it through Field Normalisation -> Transformations
I have created a transformation on a particular table(let's say Incident table) and on field(let's say short description field)

Consider my data is format :
sample1: User(13345)
sample2: 13345
sample3: 13345(User)

In any of the cases I need to extract Numeric part if it exists.
I have tried it using Transform Type as 'Replace'
Find: /regex/(/(\d+)/)
Replace: $0

 

Output required: 13345

2 REPLIES 2

Sourabh26
Giga Guru

Hi,

 

Try below code.

 

var str = 'User(13345)';
var matches = str.match(/(\d+)/);
gs.info(matches);

 

Mark this as Helpful/Correct, if Applicable.

 

Regards,

Sourabh

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Vamsi,

There's also a need to check for when there's no numeric value.

function extractNumeric(str) {
  var result = '';
  var matches = str.match(/(\d+)/);
  if (matches) {
    result = matches[0];
  }
  return result;
}

gs.info(extractNumeric('User(123345)'));