Linux – Add, replace or delete something/everything between two strings with regexxer

linuxperlregex

I'm using regexxer to translate an application that use .php files. In accordance to the webpage it's based on usage and syntax of Perl regular expressions. It looks more to be applied to Perl code. I'm not experienced in regex and the most "complex" things I've achieved are:

Search: 'Name must be between (\d+) and (\d+) characters!'
Replace: '¡Nombre debe tener entre $1 y $2 caracteres!'

and:

Search: 'Password(:|')
Replace: 'Contraseña$1

With +200 files and 5/50 lines/vars each one I can save hours/days with less and more complex regex. How can I do this?:

Search: '(any word) must be between (\d+) and (\d+) (other word)!'
Replace: '¡$1 debe tener entre $2 y $3 $4!'

and this? (find any string that begins with 'Warning: ' and ends with '!' in order to replace 'Warning: ' with 'Advertencia: ¡'):

Search: 'Warning: File not found!'
Replace: 'Advertencia: ¡Archivo no encontrado!'

Please help me what to type into regexxer.

Best Answer

This regex matches between two strings

(?<=first).*?(?=last)

e.g. it matches for this text, between first and last. firstfgdfgfddlast

tested in http://gskinner.com/RegExr/ (took me a while to find an online regex tester that worked! I guess many don't support lookbehind. But that one is good).

Improvement added by quantme-
In regexxer:

Search: 'Warning: (.*?)!'
Replace: 'Advertencia: ¡$1!'
Related Question