preg-match-all

How to individually match all numbers that immediately follow a keyword?

流过昼夜 提交于 2019-12-11 13:43:26
问题 I have this string: 28.6MH\/s 27.3MH\/s | Temp(C): 64 66 61 64 63 | Fan: 74% 76% 69% 75% 72% | HW: 21 21 21 and I want to extract the Temp values, but I can't figure out what I'm doing wrong. The expression that I came up with (and doesn't work) is: ((?<temp>\d\d)(?!\.).+(?!Fan))+ Debuggex Demo 回答1: Pattern: /(?:\G(?!^)|Temp\(C\):) \K\d+/ (Demo) Code: (Demo) $in='28.6MH\/s 27.3MH\/s | Temp(C): 64 66 61 64 63 | Fan: 74% 76% 69% 75% 72% | HW: 21 21 21 '; var_export(preg_match_all('/(?:\G(?!^)

How to clear preg_match_all from empty array values

旧城冷巷雨未停 提交于 2019-12-11 12:58:28
问题 I am using preg_match_all to build the array for shortcodes and it works fine but it also returns arrays with empty values see here please https://eval.in/141437 Using this match witch I am sure is casuing the extra empty arrays #\[link(.*?)link\=\"(.*?)\"(.*?)text\=\"(.*?)\"\]#e How can I clear those. I tried array_filter but it did not work. Thank you! 回答1: () represent a capture group and will be represented in the $matches array even if it is empty. Either get rid of the () around the

permutation using regular expression in php

让人想犯罪 __ 提交于 2019-12-11 12:18:56
问题 Is there any way to get permutation of all words in a string using only regular expression in php. For example: for input like "How to remove pain in human knee" I want output as: "How To", "How","pain knee","remove knee","knee pain","in remove","human pain knee", etc. 回答1: Using regex will only serve to slow down the process. I have written a function based on the powerSet() function posted by Yada @ https://stackoverflow.com/a/27968556/2943403) Code: (Demo) function permStacker($array){

How do I remove duplicates from a preg_match_all generated array?

白昼怎懂夜的黑 提交于 2019-12-11 09:47:46
问题 How do I remove duplicates from a preg_match_all generated array? Current array Array ( Array ( 'font-family: "Comic Sans";', 'font-weight: bold;', 'font-weight: normal;', 'font-family: "Comic Sans";', 'font-weight: normal;' ) Array ( 'font-family', 'font-weight', 'font-weight', 'font-family', 'font-weight' ) Array ( '"Comic Sans"', 'bold', 'normal', '"Comic Sans"', 'normal' ) ) As you can see there are several duplicate values. The new array without the duplicate values should look like this

Content from large number of web pages into array (PHP)

独自空忆成欢 提交于 2019-12-11 09:16:06
问题 I have an array ($x) containing 748 URL:s. Now, I want to fetch a specific part from each page and put all those parts into a new array. That is, an array containing 748 pieces of text, each from a different URL defined in array $x. Here's the code I've got so far: foreach ($x as $row) { $contents = file_get_contents($row); $regex = '/delimiter_start(.*?)delimiter_end/s'; preg_match_all($regex, $contents, $output); } If I var_dump $output I get a strange array that endlessly keeps looping

PHP return preg_replace() inside of foreach?

南笙酒味 提交于 2019-12-11 08:44:31
问题 hey, i have no idea what I'm doing wrong. I have a regexp pattern that looks for a youtube url inside or [track=url]. I'm returning a youtube embed-code if the regexp is matched. I need to have a unique ID for each video. I'm creating this ID with a simple count variable inside my preg_match_all foreach loop. The $uniqueID that I need for each video works just fine. If I have 3 [track=url] inside my $content I get 3 different id's echoed out (player_1, player_2, player_3, etc...) However ONLY

PHP RegEx won't pick up question mark

百般思念 提交于 2019-12-11 08:16:21
问题 I am trying to match urls in a string using the PHP function "preg_match_all". It works fine, except it will not match urls with question marks in them. For example, this will match fine: http://espn.com/mlb But this will not match: http://espn.com/mlb?player=71 Here is the regex I am using, $regexUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; I cannot figure out why the question mark is not being picked up by the \S. I've tried a lot of different expressions

Create an array based on a specific string in PHP

℡╲_俬逩灬. 提交于 2019-12-11 06:37:21
问题 I have a problem, I would like to ask for this string: [NAME: abc] [EMAIL: email@gm.com] [TIMEFRAME: 3 weeks] [BUDGET: 1000 dollars] [MESSAGE: bla bla bla] Replace it with an array in the form: array( 'NAME' => 'abc', 'EMAIL' => 'email@gm.com', 'TIMEFRAME' => '3 weeks', 'BUDGET' => '1000 dollars', 'MESSAGE' => 'bla bla bla' ); I tried to do something like this: $content = str_replace(array('[', ']'), '', '[NAME: abc] [EMAIL: email@gm.com] [TIMEFRAME: 3 weeks] [BUDGET: 1000 dollars] [MESSAGE:

Regular Expression in PHP: How to create a pattern for tables in html

允我心安 提交于 2019-12-11 06:23:41
问题 I am using latest PHP. I want to parse HTML page to get data. HTML: <table class="margin15" style="margin-left: 0pt; margin-right: 0pt;" width="100%" align="left" border="0" cellpadding="0" cellspacing="0"> TRs, TDs, Data </table> <table class="margin15" style="margin-left: 0pt; margin-right: 0pt;" width="100%" align="left" border="0" cellpadding="0" cellspacing="0"> TRs, TDs, Data </table> <table class="margin15" style="margin-left: 0pt; margin-right: 0pt;" width="100%" align="left" border=

preg_match_all not matching all possibilities

人走茶凉 提交于 2019-12-11 06:19:56
问题 I'm trying to retrieve all matches however I am only receiving one Here is my string $html = '<p> This is my Home Page.</p><p><span style="line-height: 1.42857;">{{ type="slider" }} </span></p><p> </p>'; If you see string contain {{ type="slider" }} , now if i write this string only once i am getting my expected result, but if i write it multiple times in html sting like {{ type="slider" }} {{ type="banned" }} {{ type="testimonial" }} $html = '<p> This is my Home Page.</p><p><span style="line