Regex 从Wordpress插件文件夹中grep版本号
grep正则表达式提取版本号的方式是什么Regex 从Wordpress插件文件夹中grep版本号,regex,grep,wordpress,Regex,Grep,Wordpress,grep正则表达式提取版本号的方式是什么 Version: 3.1.5 * Version: 3.1.5 将输出3.1.5 但它不应该抓住喜欢的人 MIME-Version: 1.0\n 这是我的grep命令 grep -ri 'version\s*:\s*[0-9\.]\w*' /home/test/public_html/wp-content/plugins/plugin_name @阿努巴瓦 woocommerce是一个文件夹。此文件夹下有文件woocommerce.php *
Version: 3.1.5
* Version: 3.1.5
将输出3.1.5
但它不应该抓住喜欢的人
MIME-Version: 1.0\n
这是我的grep命令
grep -ri 'version\s*:\s*[0-9\.]\w*' /home/test/public_html/wp-content/plugins/plugin_name
@阿努巴瓦
woocommerce
是一个文件夹。此文件夹下有文件woocommerce.php
**woocommerce.php的内容**
* Plugin Name: WooCommerce
* Plugin URI: http://www.woothemes.com/woocommerce/
* Description: An e-commerce toolkit that helps you sell anything. Beautifully.
* Version: 2.3.8
* Author: WooThemes
* Author URI: http://woothemes.com
* Requires at least: 4.0
* Tested up to: 4.2
工作
grep -rPo "(^|\s|^\*)+(Version\s*:\s*)\K([0-9]|\.)*(?=\s|$)" /home/test/public_html/wp-content/plugins/woocommerce/
您可以使用grep-oP
(PERL风格的正则表达式):
Version:
匹配文本Version:
后跟0或更多空格\K
重置匹配信息,并且\S+
匹配版本号
grep -rPo "(^|\s|^\*)+(Version\s*:\s*)\K([0-9]|\.)*(?=\s|$)" /home/test/public_html/wp-content/plugins/attachments/
说明:
-p
表示PCRE,-o
表示仅获取行的匹配部分
(^ |\s)+(版本:)
将在开始处匹配版本
,或一个或多个空格,然后\K
将放弃匹配
([0-9]|\)*
将匹配任何数字或
零次或多次,这是我们想要的
- 前一个标记后面将跟任何空格字符或行尾
它无法进行文件夹搜索。我想对maxdepth为1的insider插件文件夹进行grep。grep
中的文件夹搜索是什么?你能在你的问题中显示plugin\u name
的内容吗。grep-oP'Version:\K\S+'/home/test/public\u html/wp content/plugins/woocommerce
我需要查看woocommerce
的内容来检查为什么这个grep不适合你。我有更新问题,内容是woocommerce
grep -rPo "(^|\s|^\*)+(Version\s*:\s*)\K([0-9]|\.)*(?=\s|$)" /home/test/public_html/wp-content/plugins/attachments/