将正则表达式与“msggrep”一起使用
我有一个 PO 文件,其内容如下:
msgid "or"
msgstr "or-translation"
msgid "orand"
msgstr "orand-translation"
我需要获取给定 msgid 的翻译。使用命令“msggrep -K -e 'orand' template2.pot”我得到了“orand”的翻译,这是可以的。
但是当我使用“msggrep -K -e 'or' template2.pot”时,if 返回两个翻译('or' 和 'orand')。命令“msggrep -K -e '^or' template2.pot”按预期工作,返回两个翻译,但“msggrep -K -e '^or$' template2.pot”只是失败,因为它什么也不返回。似乎“$”字符破坏了 msggrep 正则表达式解析器。
我尝试过使用其他 msggrep 标志(如 -F、-E...),但它们都从文件中读取测试模式,这对于我的实际需求来说是不可接受的。我正在使用 msggrep 0.14.6 (并且我无法更新到更新的库)。
有人知道如何使用 msggrep 获得“orand”的翻译吗?
I have a PO file with a content like:
msgid "or"
msgstr "or-translation"
msgid "orand"
msgstr "orand-translation"
I need to obtain the translation of a given msgid. Using the command "msggrep -K -e 'orand' template2.pot" I get the translation for 'orand', and this is ok.
But when I use "msggrep -K -e 'or' template2.pot" if returns both translation ('or' and 'orand'). The command "msggrep -K -e '^or' template2.pot" work as expected, returning both translations, but "msggrep -K -e '^or$' template2.pot" just fail becouse it returns nothing. Seems like the '$' character breaks msggrep regular-expression parser.
I have tried with other msggrep flags (like -F, -E...) but all of them reads testing patterns from a file, and it is unacceptable for my actual needs. I'm using msggrep 0.14.6 (and I can't update to a more recent library).
Does someone knows how can I get the translation for 'orand' using msggrep?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以改用词尾检查:
这可确保
'or'
之后有一个词边界,因此它不会匹配'orand'
。You can use an end-of-word check instead:
Which makes sure there is a word boundary after
'or'
, so it won't match'orand'
.