const regex = /Title: (?<Title>.*$)[\s\S]*(?<PhoneNumber>\d{10})[\s\S]*When: (?<Date>.[a-zA-Z]*\s.\d*\s.[a-zA-Z]*\s\d*)\s(?<Time>.[0-9]*:[0-9]*[am|pm]* \S [0-9]*:[0-9]*[am|pm]*)[\s\S]*Where: (?<Where>.*?.*$)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Title: (?<Title>.*$)[\\s\\S]*(?<PhoneNumber>\\d{10})[\\s\\S]*When: (?<Date>.[a-zA-Z]*\\s.\\d*\\s.[a-zA-Z]*\\s\\d*)\\s(?<Time>.[0-9]*:[0-9]*[am|pm]* \\S [0-9]*:[0-9]*[am|pm]*)[\\s\\S]*Where: (?<Where>.*?.*$)', 'gm')
const str = `You have been invited to the following event.
Title: לקוח רועי
0544710385
When: Sat 28 Nov 2020 9:30pm – 10:30pm Israel Time
Where: Mazal Keshet Street, Mazal Keshet St, Hod Hasharon, Israel
Joining info: Join with Google Meet
https://meet.google.com/ngv-fxvo-oyt
Calendar: mplmp5e1vpvapd7fl5euj7g81ytfzlem@hook.integromat.com
Who:
* ecmanager8@gmail.com- organiser
* My Automation
Event details:
https://calendar.google.com/calendar/event?action=VIEW&eid=NnNvbTJjMW82Z3I2YWJiMmNvbzM2YjlrYzloNmFiOW82Y3FtYWJiMWM0cDNnb3I1NzBzMzJkOXA2YyBtcGxtcDVlMXZwdmFwZDdmbDVldWo3ZzgxeXRmemxlbUBob29rLmludGVncm9tYXQuY29t&tok=MjAjZWNtYW5hZ2VyOEBnbWFpbC5jb20yODdjNWU1ZjU2ZjVjNWIwZmE4NmYwOTMxNzY5NTczMGNhNGJiN2E3&ctz=Asia%2FJerusalem&hl=en_GB&es=0
Invitation from Google Calendar: https://calendar.google.com/calendar/
You are receiving this courtesy email at the account
mplmp5e1vpvapd7fl5euj7g81ytfzlem@hook.integromat.com because you are an
attendee of this event.
To stop receiving future updates for this event, decline this event.
Alternatively, you can sign up for a Google Account at
https://calendar.google.com/calendar/ and control your notification
settings for your entire calendar.
Forwarding this invitation could allow any recipient to send a response to
the organiser and be added to the guest list, invite others regardless of
their own invitation status or to modify your RSVP. Learn more at
https://support.google.com/calendar/answer/37135#forwarding`;
// 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