I'm trying to isolate all the usernames from a server log.
我试图从服务器日志中隔离所有用户名。
How can I find the inverse of regex query for a string?
如何找到字符串的正则表达式查询的反转?
I have
/(?<=username=)(.*)(?=&password)/g
and that will find me tom and jerry from the following
这将从下面找到我汤姆和杰里
"POST /v1/login HTTP/1.1" 403 24 "-" "curl/7.47.0" "-" "username=tom&password=tom1q2w" "POST /v1/login HTTP/1.1" 403 24 "-" "curl/7.47.0" "-" "username=jerry&password=jerryqawsed"
“POST / v1 / login HTTP / 1.1”403 24“ - ”“curl / 7.47.0”“ - ”“username = tom&password = tom1q2w”“POST / v1 / login HTTP / 1.1”403 24“ - ”“curl / 7.47.0“” - “”username = jerry&password = jerryqawsed“
But then I want to replace the inverse string with \n, so I'll have a column of usernames.
但后来我想用\ n替换反向字符串,所以我将有一列用户名。
1 个解决方案
#1
2
You may use
你可以用
.*?username=(.*?)&password.*
and replace with $1\n
. See the regex demo
并替换为$ 1 \ n。请参阅正则表达式演示
Details:
-
.*?
- any 0+ chars other than line break chars as few as possible up to the first... -
username=
- literal char sequence -
(.*?)
- Capturing group 1 matching any 0+ chars other than line break chars as few as possible up to the first... -
&password
- literal char sequence -
.*
- any 0+ chars other than line break chars as many as possible.
。*? - 除了换行符之外的任何0 +字符尽可能少到第一个...
username = - 文字字符序列
(。*?) - 捕获第1组匹配除了换行符之外的任何0+字符,尽可能少到第一个...
&password - 文字字符序列
。* - 除了换行符之外的任何0+字符尽可能多。
The $1
is a replacement backreference inserting the value inside Group 1 back into the resulting string.
$ 1是替换反向引用,将Group 1中的值插回到结果字符串中。
#1
2
You may use
你可以用
.*?username=(.*?)&password.*
and replace with $1\n
. See the regex demo
并替换为$ 1 \ n。请参阅正则表达式演示
Details:
-
.*?
- any 0+ chars other than line break chars as few as possible up to the first... -
username=
- literal char sequence -
(.*?)
- Capturing group 1 matching any 0+ chars other than line break chars as few as possible up to the first... -
&password
- literal char sequence -
.*
- any 0+ chars other than line break chars as many as possible.
。*? - 除了换行符之外的任何0 +字符尽可能少到第一个...
username = - 文字字符序列
(。*?) - 捕获第1组匹配除了换行符之外的任何0+字符,尽可能少到第一个...
&password - 文字字符序列
。* - 除了换行符之外的任何0+字符尽可能多。
The $1
is a replacement backreference inserting the value inside Group 1 back into the resulting string.
$ 1是替换反向引用,将Group 1中的值插回到结果字符串中。