import re
regex = re.compile(r"translate\(\'([^)]*)\',")
test_str = ("<div class=\"row\">\n"
" <div class=\"col-md-12\">\n"
" <div class=\"content-title\"><?php echo $this->translate('Contattaci'); ?></div>\n\n"
" <?php if ( $this->messageProcessed && $this->sendError ): ?>\n"
" <div class=\"alert alert-danger\">\n"
" <h4><span class=\"glyphicon glyphicon-exclamation-sign\"></span> <?php echo $this->translate('Errore Invio Messaggio'); ?></h4>\n"
" <?php echo $this->translate('Spiacenti, si é verificato un errore durante l’invio del messaggio'); ?>.\n"
" <p class=\"error\"><?php echo $this->sendError; ?></p>\n"
" </div>\n"
" <?php elseif ( $this->messageProcessed & !$this->sendError ): ?>\n"
" <div class=\"alert alert-success\">\n"
" <h4><span class=\"glyphicon glyphicon-ok-circle\"></span> <?php echo $this->translate('Messaggio Inviato'); ?></h4>\n"
" <?php echo $this->translate('Grazie per il tuo messaggio. Risponderemo nel piú breve tempo possibile'); ?>.\n"
" </div>\n"
" <?php else: ?>\n"
" <div class=\"well well-sm\">\n"
" <?php echo $this->translate('Compila il modulo seguente per inviarci un tuo messaggio.'); ?><br />\n"
" <?php echo $this->translate('Sarà nostra premura rispondere nel minor tempo possibile per fornirti tutte le informazioni di cui puoi necessitare.'); ?>\n"
" </div>\n"
" <?php if ( $this->getSetting('site_phone') ): ?>\n"
" <div class=\"alert alert-info alert-dismissable\">\n"
" <button aria-hidden=\"true\" data-dismiss=\"alert\" class=\"close\" type=\"button\">×</button>\n"
" <span class=\"glyphicon glyphicon-info-sign\"></span> <?php echo $this->translate('Se preferisci, puoi contattarci telefonicamente al numero <b>%s</b>', $this->getSetting('site_phone')); ?>\n"
" </div>\n"
" <?php endif; ?>\n"
" <div class=\"contact-form\">\n"
" <?php echo $this->form; ?>\n"
" <div class=\"clearfix\"></div>\n"
" <p> </p>\n"
" <div class=\"small text-justify well well-sm\">\n"
" <?php echo $this->translate('I dati personali saranno trattati ai sensi del D.Lgs. 196/2003, sulla tutela delle persone e di altri soggetti rispetto al trattamento dei dati personali, il trattamento delle informazioni che ti riguardano, sarà improntato ai principi di correttezza, liceità e trasparenza e tutelando la tua riservatezza e i tuoi diritti.'); ?>\n"
" </div>\n"
" </div>\n"
" <?php endif; ?>\n"
" </div>\n"
"</div>\n")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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 Python, please visit: https://docs.python.org/3/library/re.html