1

I'm trying to get the following words (in bold) using JavaScript/jquery:

Blablablalblabla

  • Blablablalblabla: Blablablalblabla
  • Affected: Windows Vista, Windows 7
  • hxxps://Blablablalblabla

Blablablalblabla

  • Affected: Windows Vista , Windows Server 2008, Windows 7, Windows Server 2008 R2, Windows 8.1, Windows Server 2012 and Windows Server 2012 R2, Windows 10, Windows Server 2016
  • hxxps://Blablablalblabla

They are comma separated. Their appear after the string 'Affected:' and ends with the string '- https'.

So far I have tryied several regex, for example: /Affected(.*?)\n- https/g

Maybe I'm focusing worthly... any idea?

ElTête
  • 555
  • 1
  • 5
  • 15
  • What about `/Affected:\s*([^]*?)\n- https/g`? See https://regex101.com/r/GVEqVI/3. I guess you replaced `http` with `hxxp` so as not to create links in the post, right? – Wiktor Stribiżew Mar 16 '17 at 14:40

1 Answers1

0

I suggest using a [^] or [\s\S] construct to match any character, and include : and a space into the pattern.

var rx = /Affected:\s*([^]*?)\n- https/g;
var str = "Blablablalblabla  \n\n- Blablablalblabla: Blablablalblabla\n- Affected: **Windows Vista, Windows 7** \n- https://Blablablalblabla\n\n\nBlablablalblabla";
var m, res=[];
while ((m = rx.exec(str)) !== null) {
  res.push(m[1].trim());
}
console.log(res)
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563