const regex = /^\s+$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\s+$', 'gm')
const str = `
General Information
Brand:
Whirlpool
Model name:
PACW9HP
Type:
On/Off
Construction Type:
Free-Standing
Number of Speeds:
7
Mode
Cooling:
Yes
Heating:
Yes
Antibacterial Filters:
Yes
Ionization:
Yes
Sleep Function:
Yes
Conditioner Features
Recommended Area:
25 - 30 m²
Capacity Cooling (BTU):
9000
Capacity Heating (BTU):
8500
Capacity Cooling (W):
3000
Capacity Heating (W):
2000
Air Flow:
350 m³/h
Indoor Noise Level:
65
HEPA Filter:
Yes
Compressor
Refrigerant:
R410A
Type of Compressor:
Rotary
Energy Rating
Energy Efficiency Class:
A+
Remote Control
Remote Control:
Yes
Timer on / off:
Yes
Power
Power from:
Network
Voltage:
200-240 V
Cord Length:
1.2 m
Color
Color:
White
Dimensions
Dimensions (W x H x D):
448 x 743 x 400 mm
Weight
Weight:
31 kg
Warranty
Warranty:
36 Months
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions