0

我有一个文本文件,我想从中获取所有已翻译的字符串。

所有的翻译都是这样的:

_('string')

所以我有这个正则表达式:

(_\(['"].+['"]\))

哪个找到了我所有的翻译......现在我该如何反转它以便删除其他所有内容?

我最终做了:

egrep "_\('.+?)" ~myfile.py -o >> ~/Desktop/translations.txt

egrep '_\(".+?)' ~myfile.py -o >> ~/Desktop/translations.txt

我什至无法一口气完成,因为我不知道如何在 shell 中转义单引号 :(

4

1 回答 1

0

Negating a regular expression is often pretty complicated. Instead of deleting everything else with regular expressions, you are much better off finding all matches of your current regex and then joining the matches together to create a string of only the matches.

于 2012-10-11T19:51:08.243 回答