-1

I would like to extract particular piece of text MH4 from the string S12345-MH4-PX through javascript regular expressions.

The desired output should be MH4.

Dhanu Gurung
  • 8,480
  • 10
  • 47
  • 60
Narasimha
  • 21
  • 2

1 Answers1

0

You can use something like:

var input = 'S12345-MH4-PX';    
var reg = /\-(.*)-/g;

var matches = reg.exec(input);

console.log(matches[1]);
R.Costa
  • 1,395
  • 9
  • 16