# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = 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 = re.finditer(regex, test_str)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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