Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Python

r"
(?:lazy_)?gtxt\(([\"'])(?:(?!\1)[^\\]|\\.)*\1\)
"
mg

Description

Matches strings within a gettext call. Covers the following examples:

  • gtxt('i am in single-quotes')
  • gtxt('i have ' an escaped single-quote within single-quotes')
  • gtxt('i have a "double-quote" in single-quotes')
  • gtxt("i am in double-quotes")
  • gtxt("i am in double-quotes with single 'quotes'")
  • gtxt('i have an escaped double-quote " within double-quotes')

Note that gettext has been aliased to gtxt here, so change it to whatever alias you're using. I also have a lazy version of gettext, hence the optional lazy_ portion, which can be deleted.

Submitted by anonymous - 5 years ago