const regex = /translate\(\'([^)]*)\',/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('translate\\(\\\'([^)]*)\\\',', 'g')
const str = `<div class="row">
<div class="col-md-12">
<div class="content-title"><?php echo \$this->translate('Contattaci'); ?></div>
<?php if ( \$this->messageProcessed && \$this->sendError ): ?>
<div class="alert alert-danger">
<h4><span class="glyphicon glyphicon-exclamation-sign"></span> <?php echo \$this->translate('Errore Invio Messaggio'); ?></h4>
<?php echo \$this->translate('Spiacenti, si é verificato un errore durante l’invio del messaggio'); ?>.
<p class="error"><?php echo \$this->sendError; ?></p>
</div>
<?php elseif ( \$this->messageProcessed & !\$this->sendError ): ?>
<div class="alert alert-success">
<h4><span class="glyphicon glyphicon-ok-circle"></span> <?php echo \$this->translate('Messaggio Inviato'); ?></h4>
<?php echo \$this->translate('Grazie per il tuo messaggio. Risponderemo nel piú breve tempo possibile'); ?>.
</div>
<?php else: ?>
<div class="well well-sm">
<?php echo \$this->translate('Compila il modulo seguente per inviarci un tuo messaggio.'); ?><br />
<?php echo \$this->translate('Sarà nostra premura rispondere nel minor tempo possibile per fornirti tutte le informazioni di cui puoi necessitare.'); ?>
</div>
<?php if ( \$this->getSetting('site_phone') ): ?>
<div class="alert alert-info alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<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')); ?>
</div>
<?php endif; ?>
<div class="contact-form">
<?php echo \$this->form; ?>
<div class="clearfix"></div>
<p> </p>
<div class="small text-justify well well-sm">
<?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.'); ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions