Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find all msgstr which are either not empty or multilines using regexp in a po file

In a .po file, what regexp could I use to find out all msgstr lines being either

msgstr "some text"

or which spread on several lines:

msgstr ""
"some multiline text"
"goes here"

but not empty ones:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

msgstr ""

?

For the moment I’m using this:

(msgstr "[\D\s]+")|(msgstr ""[\n\D\s]+")

But it’s not fully working.

>Solution :

If all following lines should start with a double quote with at least a single character:

^msgstr (?:"[^"\r\n]+"|.*(?:\n"[^\r\n"]+")+)

The pattern matches:

  • ^ Start of string
  • msgstr Match literally
  • (?: Non capture group for 2 alternatives
    • "[^"\r\n]+" Match from an opening till closing double quote with at least one character other than a double quote or newline
    • | Or
    • .* Match the whole line
    • (?:\n"[^\r\n"]+")+ Repeat matching 1 or more lines with at least one character other than a double quote or newline
  • )Close the non capture group

Regex demo

If the following lines can also be empty:

^msgstr (?:"[^"\r\n]+"|.*(?:\n".*")+)

Regex demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading