Articles of 正则expression式

egrep匹配组不打印?

我试图创build一个bash脚本,将使用egrep grep从一个文件的行。 我已经创build了应该将我想要的信息分组的正则expression式,问题是试图获得输出。 我一直在用下面的命令testing它,但是运行时没有打印任何东西。 如何打印 – {80}和断开连接之间的多行? egrep -E "^-{80}$\r?\n?([:ascii:]*)Disconnected from Server" testing.txt 文件:testing.txt Connected to the server: name here Some header text. More text to go though… ——————————————————————————– The information that I want, would be in here; Including this line as well #$ and this one. Disconnected from Server…

Postfix虚拟域名:如何接受除两个以外的所有子域名?

假设我的Postfix服务器提供域example.com ,我希望它接受example.com的所有子域的邮件,除了mail.example.com和in.example.com 。 起初,我试过使用排除这两个子域的正则expression式: (?(?!mail|in).+\.example.com) 但它没有工作。 我不确定问题是否与正则expression式或Postfix的正则expression式引擎是否不支持条件,所以我决定尝试使用表文件的条件。 在这一点上,我的桌子看起来像这样: /等/后缀/ virtual_domains: if !/(in|mail)\.example\.com/ /.+\.example\.com/ OK endif /etc/postfix/main.cf文件: virtual_alias_domains = regexp:/etc/postfix/virtual_domains 但它也没有工作。 我究竟做错了什么?

NGINX Proxy_Pass删除url子string

我有一个NGINX作为反向代理。 我需要从URL中删除子串string_1,其余的URL是可变的。 例: Origin: http://host:port/string_1/string_X/command?xxxxx Destination: http://internal_host:port/string_X/command?xxxxx nginx.conf: location /string_1/ { proxy_pass http://internal_host:port/$request_uri$query_string; 谢谢, @pcamacho

从bash中的GitHub url中提取存储库名称

鉴于任何GitHub仓库urlstring像: git://github.com/some-user/my-repo.git 要么 [email protected]:some-user/my-repo.git 要么 https://github.com/some-user/my-repo.git bash从以下任何string中提取存储库名称my-repo的最佳方法是什么? 该解决scheme必须适用于上面指定的所有types的url。 谢谢。

如何查找不包含给定searchstring的文件

我有一个命令,查找所有包含string“Font”的PDF文件 find /Users/me/PDFFiles/ -type f -name "*.pdf" -exec grep -H 'Font' '{}' ';' 我怎样才能改变这个命令,使之反转? 查找不包含searchstring“Font”的所有PDF文件

Apache的位置匹配负面的正则expression式

我试图通过Apache暴露一个位置。 通常情况下,我的虚拟主机中有这个块 <Location /> AuthType Basic AuthUserFile /web/.htpasswd AuthName "Test Site" Require valid-user </Location> 这工作得很好 – 一切服务需要一个有效的用户。 现在我想公开一个不需要身份validation的服务,所以我正在寻找一种方法来使除/服务之外的所有位置都需要身份validation。 我一直在玩LocationMatch,但是我不清楚它在做什么。 <LocationMatch ^/(?!services)[^.]*$> AuthType Basic … </LocationMatch> 允许/服务及其下的所有内容跳过LocationMatch,但是它具有允许example.com/.somefile绕过LocationMatch块的副作用。 另外,当我尝试 <LocationMatch ^/(?!services)> AuthType Basic … </LocationMatch> 一切(包括/服务)都由LocationMatch匹配。 我会很感激,如果有人能告诉我什么[^。*]类做的第二个testing没有,以及如何只暴露/服务,同时保持所有其他path进行身份validation。

为什么$ 1反向引用在没有子组的情况下重写?

我正在使用的人有一个像SVN这样的RewriteRule,如下所示: RewriteRule ^admin/ebay.*$ /yii.php/$1 [L] 我警告过他可能无法工作,因为比赛中没有对应于$ 1反向引用的子组。 它确实有用,而我感到困惑。 我很确定他的意图是以下两种情况之一: RewriteRule ^admin/ebay.*$ /yii.php/$0 [L] # $0 is whole match …要么… RewriteRule ^admin/ebay(.*)$ /yii.php/$1 [L] # $1 subgroup Apache是​​否对我从来不知道的反向引用做出假设? 为什么他的重写规则(最重要的)工作?

inotifywait使用和排除

我想通过inotifywaitrecursion地监视创build或修改文件的任何事件的特殊path,但我不知道我的问题是什么。 我有一些我想排除的文件夹。 watchpath -> folder1 -> file1 -> ingnorefile1 [IGNORE] -> ignorefolder1 [IGNORE] 我如何使用正则expression式正确排除它们? inotifywait -mr –exclude '(ignorefolder1|folder1\/ingnorefile1)' -e modify -e create -e delete . | while read date time dir file; do 什么是正确的正则expression式来实现我的目标?

Apache MatchRedirectexception正则expression式

我想redirect任何URL为Https并且没有以“system_”开头的URL到同一个URL。 对于这个url exapmle: https://exsite.tld/some/thing/that/not/start/with/pattern 至 : http://exsite.tld/some/thing/that/not/start/with/pattern 但是这个url: https://exsite.tld/system_aas3f4 不应该redirect。 我尝试: RedirectMatch ^/?((?!(system_)).*) http://exsite.tld/$1 但它不会工作。 我不知道有什么问题。

在不同的Apache版本之间,正则expression式负面预测function对mod_rewrite不起作用

我有一个mod_rewrite行在Apache 2.2下工作,但不在Apache 1.3下: RewriteRule ^(?!index.php)(?!skin/)(?!js/)(.+) /index.php?file=$1 [NC,L] 如果我丢失了方括号之间的负向预测组件,我将失去500个状态码。 GoDaddy不会升级这个客户端软件包(叹气)的httpd,所以有人得到了一个解决scheme,可以在1.3的工作(并不太麻烦:P)? 或者甚至更好,任何人都可以解释这里可能会发生什么? 我仍然很好奇,因为我找不到在1.3中使用的Perl正则expression式引擎不支持负面预测的任何信息…