use strict;
my $str = '[mysqld]
skip-grant-tables # k
bind-address=127.0.0.1
port = 3307 # test
basedir=C:\\Program Files (x86)\\MySQL\\
datadir=C:\\Program Files (x86)\\MySQL\\data\\
default-storage-engine=INNODB
sql-mode= " STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,test NO_ENGINE_SUBSTITUTION" #test
max_connections=1000
tmp_table_size=1G
max_heap_table_size=1G
join_buffer_size=1M
query_cache_size =50M
query_cache_limit=50M
max_allowed_packet = 104857600
port =
= fh
thread_cache_size=8
#*** MyISAM Specific options
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=35M
key_buffer_size=25M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=256K
#*** INNODB Specific options ***
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=50M
innodb_buffer_pool_size=1000M
innodb_log_file_size=300M
innodb_thread_concurrency=8
innodb_flush_method=normal
innodb_autoinc_lock_mode=0
test=0
';
my $regex = qr/^(?!\s*$)\s*(?!\s)([^#\n\[=]+?)\s*?(?>#.*?$|(?>=\s*$|=\s*?(?:#?|(".*?"|[^\s].*?)\s*?)(?:\s*#.*?$)*?$)?$)/mip;
if ( $str =~ /$regex/g ) {
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