I'm looping through a number of .PHP files, treating them as plain text, and I'm attempting to locate text arguments of certain functions.
The functions in the PHP files are all called by using L10n::
and then take string arguments.
Examples of the text that I'm trying to find are below.
I've had the most luck at finding this correctly using the following regex lines.
pattern = re.compile("L10n::[w]+((?:'(.*?)'),?s?(?:'(.*?)')*", re.MULTILINE | re.IGNORECASE | re.DOTALL)
OR
pattern = re.compile("\L10n::(.*?)('(.*?)')", re.MULTILINE | re.IGNORECASE | re.DOTALL)
barL10n::__('Double _')baz
barL10n::esc_attr__('Escape Attributes __')baz
barL10n::esc_html__('Escapted HTML __')baz
barL10n::_e('Echos')baz
barL10n::esc_html_e('Echo Escaped HTML')baz
barL10n::_x('Underscore X')baz
barL10n::_ex('Echo underscore x')baz
barL10n::esc_attr_x('Escape Attribute X')baz
barL10n::esc_html_x('Escaped HTML X')baz
barL10n::_n('Nothing')baz
barL10n::_nx('No X')baz
barL10n::_n_noop('N No-Op')baz
barL10n::_nx_noop('No X No-Op')baz
With that being said, some take multiple arguments
barL10n::_n('Text 1', 'Text 2', $variable)
In these instances I want Text 1 and Text 2, but not $variable.
To make it more fun... sometimes the arguments aren't all on one line.
barL10n::_n(
'Text 1',
'Text 2',
$variable
)
The first regex pattern I had above fails if the text has an escaped ' inside it, such as 'This looks at people that weren't here'
The second regex patter I had above fails if there's multiple text variables. (It also brings up the _n section, but that's ok)
Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire