const regex = /(?P<headers>.*)[\r\n][\r\n](?P<content>.*)/gmis;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?P<headers>.*)[\\r\\n][\\r\\n](?P<content>.*)', 'gmis')
const str = `------WebKitFormBoundary3JCHTJWwvnOcvnSv
Content-Disposition: form-data; name="_format"
json
------WebKitFormBoundary3JCHTJWwvnOcvnSv
Content-Disposition: form-data; name="rid"
1
------WebKitFormBoundary3JCHTJWwvnOcvnSv
Content-Disposition: form-data; name="avatar"; filename="carlingford.jpg"
Content-Type: image/jpeg
���p��
��T!1"AQa2q�#B�� R�\$3b�C���%r�4S�&�5c
Ds��'ET�d6U��� ��L!1AQaq"��2����#��BR�b\$3r����C%4S��s�&5DTc���?�g������F΅%v9��Ge�9�С@#B�'�y�4!p|hPW%<�8�:n��9�hI�B;�Ж�:R{�8Ћ(�m�:m�*����0��vƄ#��?'B���BQ����BGo}
;#�a#�΄U��W�x?�E��H��:��#Ռ�t�L�6C�u ��#�R����22����n�c���B�@3ƅ"��ZRN�dv΄�����Д��pB��'B]�rҥ�����Q���)P�� �R�����R9Y�I&��� =���X?�bI�u��ĮQ���!C�'dn�}��-n�s�j8 �c\$����Q����\$�q��� �@�J9\$ryԁj�pN�9���B8+*��v�Sih�J}[�W��ґ���R�r�?��h�I�J!�P�?J��+��T���+��Q�)�m
od`;
// 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