use strict;
my $str = '----------------------------------------------
SESSION SUMMARY
----------------------------------------------
Representatives:
Amoz Abraham (ID: 23)
Jose Sandoval (ID: 25)
Customer Name: [Pinned] SOUTHLAWN02
Customer\'s Public IP: 174.110.83.140:56969
Customer\'s Private IP: 10.5.65.90
Session Start Time: 2020-05-15 17:03:22 US/Pacific
Session End Time: 2020-05-15 17:11:37 US/Pacific
Duration: 00:08:15
# Files Transferred: 0
# Files Moved: 0
# Files Deleted: 0
----------------------------------------------
SYSTEM INFORMATION RETRIEVED
----------------------------------------------
## General ##
Version: Windows 10 Pro x64
Computer Name: SOUTHLAWN02
System BIOS:
Processor 1 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 2 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 3 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 4 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 5 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 6 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Default Browser: Google Chrome
Default Browser Version: 81.0.4044.138
Default Browser Location: C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe
Windows® Directory: C:\\Windows
System Directory: C:\\Windows\\system32
Time Zone: Eastern Daylight Time
';
my $regex = qr/Representatives:\s+(?<rep_name>.*)\(.*\)\s+((?<rep2_name>.*)?\s+\()?/p;
if ( $str =~ /$regex/ ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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 Perl, please visit: http://perldoc.perl.org/perlre.html