preg-match

How to match any word in a String with Regex in PHP

柔情痞子 提交于 2019-12-20 01:35:09
问题 I have these strings. I want a regular expression to match them and return true when I pass them to preg_match function. do you want to eat katak at my hometown? do you want to eat teloq at my hometown? do you want to eat tempeyek at my hometown? do you want to eat karipap at my hometown? How do I create a pattern in regex that will match the above pattern? Like this: do you want to eat * at my hometown? Asterik (*) means any word. Here is the regex pattern that I have so far: $text = "do you

Regexp for german phone number format

安稳与你 提交于 2019-12-19 21:21:41
问题 I try to get phone numbers from string in german format. But I don't get it to full run. The input text is a full HTML-Page with lots of content, not only the numbers. Possible Formats: (06442) 3933023 (02852) 5996-0 (042) 1818 87 9919 06442 / 3893023 06442 / 38 93 02 3 06442/3839023 042/ 88 17 890 0 +49 221 549144 – 79 +49 221 - 542194 79 +49 (221) - 542944 79 0 52 22 - 9 50 93 10 +49(0)121-79536 - 77 +49(0)2221-39938-113 +49 (0) 1739 906-44 +49 (173) 1799 806-44 0173173990644 0214154914479

Get all nested curly braces

六眼飞鱼酱① 提交于 2019-12-19 10:26:04
问题 It is possible to get all content in nested curly braces from string? For example: The {quick} brown fox {jumps {over the} lazy} dog So i need: quick over the jumps {over the} lazy Better in this sequence, from most nested. 回答1: Solution The regex below will allow you to grab the content of all the nested curly braces. Note that this assumes that the nested curly braces are balanced; otherwise, it is hard to define what the answer should be. (?=\{((?:[^{}]++|\{(?1)\})++)\}) The result will be

preg_match has string size limit

半腔热情 提交于 2019-12-19 07:24:27
问题 preg_match has limit of str on PHP 5.2.5 <?php $str1 = 'a@b%c@d' . str_repeat ('=', 33326); $str2 = 'a@b%c@d' . str_repeat ('=', 33327); $regexp = '/^(.*)@(.*)%(.*)$/si'; echo preg_match ($regexp, $str1) ? "Correct " : "Wrong "; // works correctly echo "\n"; echo preg_match ($regexp, $str2) ? "Correct " : "Wrong "; // exhibits the bug echo "\n"; 回答1: preg_last_error() after the second call returns 2 (=PREG_BACKTRACK_LIMIT_ERROR) so you might want to raise this value. 来源: https://stackoverflow

preg_match has string size limit

白昼怎懂夜的黑 提交于 2019-12-19 07:24:04
问题 preg_match has limit of str on PHP 5.2.5 <?php $str1 = 'a@b%c@d' . str_repeat ('=', 33326); $str2 = 'a@b%c@d' . str_repeat ('=', 33327); $regexp = '/^(.*)@(.*)%(.*)$/si'; echo preg_match ($regexp, $str1) ? "Correct " : "Wrong "; // works correctly echo "\n"; echo preg_match ($regexp, $str2) ? "Correct " : "Wrong "; // exhibits the bug echo "\n"; 回答1: preg_last_error() after the second call returns 2 (=PREG_BACKTRACK_LIMIT_ERROR) so you might want to raise this value. 来源: https://stackoverflow

regex for validating folder name & file name

天大地大妈咪最大 提交于 2019-12-19 06:56:08
问题 I want to validate a file name Name of file or folder should not contain \ / ? % * : | " < > . Could you please suggest me the regex expression to use in preg_match()? Thanks. 回答1: It would be more efficient to use the strpbrk() function. if (strpbrk($filename, "\\/?%*:|\"<>") === FALSE) { /* $filename is legal; doesn't contain illegal character. */ } else { /* $filename contains at least one illegal character. */ } 回答2: The regex that meets your requirements: ^[^\\/?%*:|"<>\.]+$ 回答3: new

regex for validating folder name & file name

孤街浪徒 提交于 2019-12-19 06:55:25
问题 I want to validate a file name Name of file or folder should not contain \ / ? % * : | " < > . Could you please suggest me the regex expression to use in preg_match()? Thanks. 回答1: It would be more efficient to use the strpbrk() function. if (strpbrk($filename, "\\/?%*:|\"<>") === FALSE) { /* $filename is legal; doesn't contain illegal character. */ } else { /* $filename contains at least one illegal character. */ } 回答2: The regex that meets your requirements: ^[^\\/?%*:|"<>\.]+$ 回答3: new

Regular expression to detect Internet Explorer 11

ぃ、小莉子 提交于 2019-12-19 05:54:22
问题 I am using this preg_match string preg_match('/Trident/7.0; rv:11.0/',$_SERVER["HTTP_USER_AGENT"] to detect IE11 so I can enable tablet mode for it. However it returns "unknown delimiter 7". How can I do this without PHP complaining at me? 回答1: Is this really a regular expression or just a literal string? If it's just a string, you can use the strpos function instead. if (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false) { // your code } If it's a regular expression, you

Regular expression to detect Internet Explorer 11

↘锁芯ラ 提交于 2019-12-19 05:52:44
问题 I am using this preg_match string preg_match('/Trident/7.0; rv:11.0/',$_SERVER["HTTP_USER_AGENT"] to detect IE11 so I can enable tablet mode for it. However it returns "unknown delimiter 7". How can I do this without PHP complaining at me? 回答1: Is this really a regular expression or just a literal string? If it's just a string, you can use the strpos function instead. if (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false) { // your code } If it's a regular expression, you

Regex to validate date in PHP using format as YYYY-MM-DD

余生颓废 提交于 2019-12-19 02:46:07
问题 I am trying to make a date regex validator. The issue I'm having is that I'm using an input field with "date" type, which works like a charm in Chrome; it opens a calendar-like in Chrome, but in the rest it does nothing, so I decided to go for a manual input of the date for the rest. This is my error throwing message (I'm looking for YYYY-MM-DD format): $date_regex ='#^(19|20)\d\d[\- /.](0[1-9]|1[012])[\- /.](0[1-9]|[12][0-9]|3[01])$#'; $hiredate = $_POST['hiredate']; if (!preg_match($date