pcre

《Nginx系列》之青铜入门篇 反向代理 负载均衡 动静分离就是这么简单

感情迁移 提交于 2020-01-06 16:10:41
1.什么是Nginx? Nginx是一个高性能的自由、开源的HTTP和 反向代理服务器 ,特点是 占用内存少 , 并发性能强 。 nginx能干嘛? 可以作为IMAP、POP3、SMTP的代理服务器; 可以作为HTTP服务器进行网站的发布处理; 可以作为反向代理进行负载均衡的实现; 2.Nginx的安装 2.1 将Nginx相关安装包上传到服务器上 [root@localhost nginx-1.12]# ls -l 总用量 2956 -rw-r--r--. 1 root root 981687 12月 21 16:09 nginx-1.12.2.tar.gz -rw-r--r--. 1 root root 2041593 12月 21 16:09 pcre-8.37.tar.gz nginx-1.12.2.tar.gz :nginx源码包,用于安装Nginx pcre-8.37.tar.gz :Perl库, 是一个用C语言编写的正则表达式函数库 。 2.2 安装pcre 解压pcre源码安装包 [root@localhost nginx-1.12]# tar zxf pcre-8.37.tar.gz 编译安装pcre [root@localhost pcre-8.37]# ./configure checking for a BSD-compatible install...

Regex PRCE PHP preg_match_all: How do remove empty nodes in matches array?

戏子无情 提交于 2020-01-06 16:02:50
问题 $text = 'Lorem Ipsum'; $re = '/(?<AA>Any)|(?<BB>Lorem)/ui'; $nMatches = preg_match_all($re, $text, $aMatches); $aMatches will contain the following: Array ( [0] => Array ( [0] => Lorem ) [AA] => Array ( // do not include to result matches array [0] => // because have not match for this part ) [1] => Array ( [0] => ) [BB] => Array ( [0] => Lorem ) [2] => Array ( [0] => Lorem ) ) Question: Is it possible to return the array without nodes for named parts that have no matches? Array ( [0] =>

Crontab intervals preg match

核能气质少年 提交于 2020-01-06 15:27:17
问题 Purpose: Trusted user puts up a crontab line, give advice when then syntax is wrong I got this one which seems to work well: /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+\S+\s+.+\S*$/ I want to improve (learning purpose) and tried to reduce the \S+\s : /^\s*[(\S+)\s+]{6}.+\S*$/ When you look at typical crontab lines, all its values are seperated by (any amount of) 6 whitespace characters. 2-20/2 10,20 /3 * * user very -long -cryptic > comand ^\s* \S+ \s+ \S+ \s+ \S+ \s+ \S+\s+\S+\s+ \S* $

Bash How to efficiently manipulate a grep -Poz multiline output?

我是研究僧i 提交于 2020-01-05 06:50:56
问题 This is my first post on stackoverflow. \0/ I hope it's not too long of an entry. I'm writing a BASH script to regularly read, filter and output data from thousands of logfiles. Performance is important, so that's why I'm mainly using grep instead of awk or sed. grep -Poz does exactly what I want in capturing the (multiline)data using patterns that's relevant for further processing, but I'm stuck in manipulating the data to, for example, an XML-file or a SQLite3 batch-query for further

Convert Regular Expression pattern from Javascript to PCRE (perl)

荒凉一梦 提交于 2020-01-05 04:01:10
问题 This is my javascript regex pattern: url = "http://www.amazon.com/gp"; hostname = /^((\\w+):\\/\\/\\/?)?((\\w+):?(\\w+)?@)?([^\\/\\?:]+):?(\\d+)?(\\/?[^\\?#;\\|]+)?([;\\|])?([^\\?#]+)?\\??([^#]+)?#?(\\w*)/.exec(url) || []; // would return "www.amazon.com" the above regex extracting the hostname from a given url. I need this line to work using pcre (c++). as you can see, I already added another '\' to each '\' but its still doesn't work. what are the additional changes I need to do to make it

how to implement template with conditions with preg_replace

≯℡__Kan透↙ 提交于 2020-01-04 14:00:55
问题 I'm trying to implement an admin interface where manager could create advanced rules of site meta tags formation. I have a function which takes a template and replaces placeholders in it with values from $registry and applies modifiers if needed. $registy = array( 'profession_name' => 'actor', 'total_found' => 100, ); $result = preg_replace_callback('/\{([^{}:]+)(:[^{}:]+)?\}/', function($matches) use ($registry) { $result = $registry[$matches[1]] ?: $matches[0]; if (in_array($matches[2],

RegEx word performance: \w vs [a-zA-Z0-9_]

纵饮孤独 提交于 2020-01-04 05:04:26
问题 I'd like to know the list of chars that \w passes, is it just [a-zA-Z0-9_] or are there more chars that it might cover? I'm asking this question, because based on this, \d is different with [0-9] and is less efficient. \w vs [a-zA-Z0-9_] : which one might be faster in large scale? 回答1: [ This answer is Perl-specific. The information within may not apply to PCRE or the engine used by the other languages tagged. ] /\w/aa (the actual equivalent of /[a-zA-Z0-9_]/ ) is usually faster, but not

Why pcre regex is much faster than c++11 regex

天大地大妈咪最大 提交于 2020-01-04 04:55:07
问题 Some sample code. This is the c++11 part using cregex_iterator: std::chrono::steady_clock::time_point begin0 = std::chrono::steady_clock::now(); regex re("<option[\\s]value[\\s]*=[\\s]*\"([^\">]*)\"[\\s]*[^>]*>", regex::icase); int found = 0; for (std::cregex_iterator i = std::cregex_iterator(input, input + input_length, re); i != std::cregex_iterator(); ++i) { found++; if (found < 10000) continue; break; } std::chrono::steady_clock::time_point end0 = std::chrono::steady_clock::now(); This is

Regex to match anything (including the empty string) except a specific given string

自古美人都是妖i 提交于 2020-01-04 03:01:44
问题 I'd like to test whether a string contains "Kansas" followed by anything other than " State" . Examples: "I am from Kansas" true "Kansas State is great" false "Kansas is a state" true "Kansas Kansas State" true "Kansas State vs Kansas" true "I'm from Kansas State" false "KansasState" true For PCRE, I believe the answer is this: 'Kansas(?! State)' But Mysql's REGEXP doesn't seem to like that. ADDENDUM: Thanks to David M for generalizing this question: How to convert a PCRE to a POSIX RE? 回答1:

Can conditionals be used to pair balance group elements?

旧时模样 提交于 2020-01-02 16:39:48
问题 TL;DR: Is there a way to specify a conditional so that an opening element MUST match its paired closing element? Example is located on regex101.com. ===== Balancing elements in regex is typically handled through recursion. This means that nested {...{...{...}...}...} can be located. Also, PCRE allows the (?(DEFINE)...) construct, which lets you define various patterns without actually starting the match. In the regular expression # Define the opening and closing elements before the recursion