import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "translate\\(\\'([^)]*)\\',";
final String string = "<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";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html