-1

I have

HOSTNAMEA,HOSTNAMEB,HOSTNAMEC,...

I have a third party workflow tool that can do the looping but can only use regex to parse values. I'd like to get a regex that grabs each hostname and puts into it's own variable in my workflow tool so the results will be

HOSTNAMEA
HOSTNAMEB
HOSTNAMEC
...

I'm struggling to get a regex that just grabs the text block X between the commas

Stefan Freitag
  • 3,340
  • 3
  • 25
  • 30

1 Answers1

1

ever heard of \w+ if you just want the strings between the comma, you can use .split(", ") as well

var str = "HOSTNAMEA,HOSTNAMEB,HOSTNAMEC";
var res = str.match(/\w+/g);
console.log(res.join(" "));

sample code for your help

aelor
  • 9,803
  • 2
  • 27
  • 43
  • That's the best answer. You can even change it to `str.match(/\w+/g).sort();` for a sorted array. – Gil Mar 12 '14 at 07:37