preg-match-all

PHP REGEX preg_match_all every line after a particular line

匆匆过客 提交于 2019-12-20 03:15:31
问题 Here is the sample string with my regex and code: $str = "Supp Fees: ---------- Oral Glucose Glucagon OXYGEN"; $ptn = "/----------(?:\r\n(.+))+/m"; preg_match_all($ptn,$str,$matches); echo"<pre>"; print_r($matches); echo"</pre>"; I'm trying to match every line after '----------' the pattern above only returns the first line (Oral Glucose). I can repeat the '\r\n(.+)' part and return another line but there is no telling how many lines there will be. Thanks! 回答1: You could do this without regex

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

How can I do a global regular expression match in Perl?

廉价感情. 提交于 2019-12-18 09:28:43
问题 I am trying to come up with a regular expression in Perl matching multiple patterns and returning all of them like preg_match_all in PHP does. Here's what I have: $str = 'testdatastring'; if($str =~ /(test|data|string)/) { print "its found index location: $0 $-[0]-$+[0]\n"; print "its found index location: $1 $-[1]-$+[1]\n"; print "its found index location: $2 $-[2]-$+[2]\n"; print "its found index location: $3 $-[3]-$+[3]\n"; } This only gives me the first match which in this is 'test'. I

Iterating over matches from preg_match_all

落花浮王杯 提交于 2019-12-18 09:07:24
问题 I am trying to figure out the mechanics of this plugin in WordPress. I have a preg_match_all function that looks like this: preg_match_all('/(?<=\\[\\[).+?(?=\\]\\])/', $content, $matches, PREG_PATTERN_ORDER); $numMatches = count($matches[0]); for ($i = 0; $i < $numMatches; $i++) { $postSlug = $matches[0][$i]; } If I understand this correctly, count($matches[0]) assumes there is only one match in $content . My goal here is to re-write the for statement to allow for the full array of matches

How to get all captures of subgroup matches with preg_match_all()? [duplicate]

好久不见. 提交于 2019-12-17 06:46:45
问题 This question already has answers here : Get repeated matches with preg_match_all() (6 answers) Closed 10 months ago . Update/Note: I think what I'm probably looking for is to get the captures of a group in PHP. Referenced: PCRE regular expressions using named pattern subroutines. (Read carefully:) I have a string that contains a variable number of segments (simplified): $subject = 'AA BB DD '; // could be 'AA BB DD CC EE ' as well I would like now to match the segments and return them via

Extract content from each first TD in a Table

谁说胖子不能爱 提交于 2019-12-14 03:19:04
问题 I've got some HTML that looks like this: <tr class="row-even"> <td align="center">abcde</td> <td align="center"><a href="deluserconfirm.html?user=abcde"><img src="../images/delete_x.gif" alt="Delete User" border="none" /></a></td> </tr> <tr class="row-odd"> <td align="center">efgh</td> <td align="center"><a href="deluserconfirm.html?user=efgh"><img src="../images/delete_x.gif" alt="Delete User" border="none" /></a></td> </tr> <tr class="row-even"> <td align="center">ijkl</td> <td align=

Regex Preg_match_all match all pattern

笑着哭i 提交于 2019-12-13 20:07:41
问题 Here is my concern, I have a string and I need to extract chraracters two by two. $str = "abcdef" should return array('ab', 'bc', 'cd', 'de', 'ef') . I want to use preg_match_all instead of loops . Here is the pattern I am using. $str = "abcdef"; preg_match_all('/[\w]{2}/', $str); The thing is, it returns Array('ab', 'cd', 'ef') . It misses 'bc' and 'de' . I have the same problem if I want to extract a certain number of words $str = "ab cd ef gh ij"; preg_match_all('/([\w]+ ){2}/', $str); //

preg_match_all find only the firt occurence

£可爱£侵袭症+ 提交于 2019-12-13 05:36:52
问题 I created this regexp but finds only the first occurrence, where am I wrong? $pattern = '/\\[h-imagegallery id=([0-9,]+)\\]/'; $subject = 'ueihui [h-imagegallery id=4,55] jwff [h-imagegallery id=425]'; print_r($matches); the result is: Array ( [0] => [h-imagegallery id=4,55] [1] => 4,55 ) 来源: https://stackoverflow.com/questions/19236653/preg-match-all-find-only-the-firt-occurence

preg_match to match src=, background= and url(..)

≯℡__Kan透↙ 提交于 2019-12-13 05:13:54
问题 I would like to find a regular expression that could find (in given HTML) the following images: Those captured in: src="" Those captured in: src='' Those captured in: background="" Those captured in: background='' Those captured in: url("") Those captured in: url('') Those captured in: url() So far i came up with: preg_match_all("/src=((\"|'|)?(.*\.(png|gif|jpg))(\"|'|))/Ui", $strHTML, $arrMatches); preg_match_all("/background=((\"|'|)?(.*\.(png|gif|jpg))(\"|'|))/Ui", $strHTML, $arrMatches);