[英]Regex Linux /etc/group
I have a problem with a regex: I want to find every group that has the user "usager" in it. 我对正则表达式有疑问:我想找到每个包含用户“ usager”的组。 Normally in linux, the usernames are situated after the last ":" so here is the regex that I made
"[^:]+$".
通常在linux中,用户名位于最后一个“:”之后,因此这是我创建的
"[^:]+$".
正则表达式"[^:]+$".
. 。
What should I do? 我该怎么办? What could I add to my regex to find "usager"?
我可以在正则表达式中添加什么来查找“ usager”?
This should probably do it. 这可能应该做。 There's probably a better way to do it but at least it introduces you to positive lookahead
可能有更好的方法,但至少它可以使您积极向前
^\w*(?=:.*usager)
I used this site to test the regular expression: http://gskinner.com/RegExr/?34598 我使用此网站测试了正则表达式: http : //gskinner.com/RegExr/?34598
Maybe: 也许:
^([^:]*):.*\busager\b
The parentheses capture the group name; 括号捕获组名; the
\\b
marks word boundaries, so that :usager,
, :usager$
, ,usager,
and ,usager$
are all matched (where $
marks the end of the entry). \\b
标记单词边界,因此:usager,
:usager$
,, ,usager,
和,usager$
都匹配(其中$
表示条目的结尾)。 If your regex sub-species doesn't support \\b
, then you can use: 如果您的正则表达式子物种不支持
\\b
,则可以使用:
^([^:]*):.*[:,]usager(,|$)
instead, or with non-capturing parentheses: 而是使用不带括号的括号:
^([^:]*):.*[:,]usager(?:,|$)
Or appropriate variations on these themes for the sub-species of regex that you are using. 或针对您正在使用的正则表达式的子种类对这些主题进行适当的更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.