pcre

Matching optional capture groups in any order

淺唱寂寞╮ 提交于 2019-12-23 03:12:24
问题 There are many situations in parsing user input where the user has the opportunity to add several optional flags to the input which should be accepted in any order. How can this be parsed with regex so that each flag will be in it's own capture group if it is present? For example: There is a required token a , and then 3 optional tokens which can come in any order b , c , and d . Some acceptable inputs would be: a a b a c a b c a c b a b c d a d b c a c d b The capture groups should always

nginx安装

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 00:23:54
安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境。 一. gcc 安装 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装: yum install gcc-c++ 二. PCRE pcre-devel 安装 PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令: yum install -y pcre pcre-devel 三. zlib 安装 zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。 yum install -y zlib zlib-devel 四. OpenSSL 安装 OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议

Wrap first and second word in span Clases PHP

二次信任 提交于 2019-12-22 12:42:57
问题 I am using a self generated navigation using php. I need to wrap the first and second word in separate div classes. e.g. <li> <span>First</span> <span class="word">Second</span> Word </li> At the moment i can wrap the first word in a span class using $name = preg_replace('/(?<=\>)\b(\w*)\b|^\w*\b/', '<span>$0</span>', $ni->name); Does anyone know how I can alter this to wrap the first two words? 回答1: You could split the words up in an array and replace the indexes you need. // Split on spaces

PHP preg_replace() fails when a non UTF8 Character is detected

China☆狼群 提交于 2019-12-22 11:58:31
问题 PHP Regular expression fails when non UTF 8 character found! I need to strip 40,000 database records to grab a width and height value from a custom_size mysql table field. The filed is in all sorts of different random formats. The most reliable way is to grab a numeric value from the left and right side of an x and strip all non numeric values from them. The code below works pretty good 99% of the time until it found a few records with non UTF 8 characters. 31*32 and 35”x21” are 2 examples.

PHP Regexp (PCRE) - Find a set of all substrings

僤鯓⒐⒋嵵緔 提交于 2019-12-22 10:34:45
问题 I have the following string, for example: aaXXccYYeeXX_ZZkkYYmmXX_ZZnnXXooYYuuXX_ZZvv How can I find all XX.*YY.*ZZ parts in the string? (possibly by using preg_match() ) XX cc YY eeXX_ ZZ XX _ ZZkk YY mmXX _ ZZ XX _ ZZnnXXoo YY uuXX _ ZZ XX oo YY uuXX_ ZZ Plus all longer matches, as: XX cc YY eeXX_ZZkkYYmmXX_ZZnnXXooYYuuXX_ ZZ 回答1: Thank everybody for help. My solution based on 'bobbogo' solution. Thank you. Regular expression: (?=(XX.*?YY.*?ZZ))(?=(.*ZZ)) Result (from RegexBuggy): 1

PHP - support for multibyte safe regular expressions

梦想的初衷 提交于 2019-12-22 09:34:35
问题 PHP supports regular expressions in three ways: POSIX ERE, now removed in PHP 7+ PCRE which is a core component, but not always multibyte safe Multibyte String, which is not enabled by default Today the web is Unicode, and PHP is too since 5.6 because of i18n. While PHP itself is known to be abysmally bad in supporting Unicode, Intl provides access to the relieving ICU library. To avoid the long wait for UString and repetition (and memory) when doin' it right, I prefer Intl and leave out

How can I link my C code with the PCRE library? (Linker errors currently being thrown.)

旧时模样 提交于 2019-12-22 05:51:14
问题 The Problem Note: I originally had this problem in a much larger project; so I pared the code down to the test case you see below. I cannot figure out how to get the following test code to compile. Specifically, it appears as if the linker cannot find the PCRE library (see below for how PCRE was configured). And this despite the explicit -L/usr/local/lib -lpcre being passed to the linker (PCRE is installed in the /usr/local directory structure). What am I doing wrong? :-( The console output

Antimatch with Regex

大憨熊 提交于 2019-12-21 21:55:04
问题 I search for a regex pattern, which shouldn't match a group but everything else. Following regex pattern works basicly: index\.php\?page=(?:.*)&tagID=([0-9]+)$ But the .* should not match TaggedObjects . Thanks for any advices. 回答1: (?:.*) is unnecessary - you're not grouping anything, so .* means exactly the same. But that's not the answer to your question. To match any string that does not contain another predefined string (say TaggedObjects ), use (?:(?!TaggedObjects).)* In your example,

How does regular expression engine parse regex with recursive subpatterns?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 15:07:32
问题 This regular expression matches palindromes: ^((.)(?1)\2|.?)$ Can't wrap my head around how it works. When does the recursion end, and when regex breaks from the recursive subpattern and goes to "|.?" part? Thanks. edit: sorry I didn't explain \2 and (?1) (?1) - refers to first subpattern (to itself) \2 - back-reference to a match of second subpattern, which is (.) Above example written in PHP. Matches both "abba" (no mid palindrome character) and "abcba" - has a middle, non-reflected

How does regular expression engine parse regex with recursive subpatterns?

ⅰ亾dé卋堺 提交于 2019-12-21 15:01:05
问题 This regular expression matches palindromes: ^((.)(?1)\2|.?)$ Can't wrap my head around how it works. When does the recursion end, and when regex breaks from the recursive subpattern and goes to "|.?" part? Thanks. edit: sorry I didn't explain \2 and (?1) (?1) - refers to first subpattern (to itself) \2 - back-reference to a match of second subpattern, which is (.) Above example written in PHP. Matches both "abba" (no mid palindrome character) and "abcba" - has a middle, non-reflected