preg-match-all

preg_match_all

Could some one explain this to me i am not familiar with preg_match_all filters, this code works fine except it does not return a negative value if one of the latitudes and longitudes is negative. if ( preg_match_all( "#<td>\s+-?(\d+\.\d+)\s+</td>#", $output, $coords ) ) { list( $lat, $long ) = $coords[1]; echo "Latitude: $lat\n...

What is wrong with this PHP expression?

Can someone explain to me why the following returns empty arrays? $reg = "/(\[{(false|true)};{.+};{\d}\])+/"; preg_match_all($reg,"[{false};{abcde};{10}][{true};{fghij};{10}]",$matches); print_r($matches); ...

Reproduce Smarty foreach with Php preg_match_all

Hi, I would like to reproduce the "Smarty foreach" comportment. The tpl file content is ($tplContent) : {foreach from=$tabMethodTest item=entry} /** * @todo Implement test{$entry.name}(). */ public function test{$entry.name}() { $this->markTestIncomplete("This test has not been implemented yet."); } {/fore...

How can I select the tag-name and attributes AND values of those attributes with ONE regular expression?

Hi, I have the following Regular Expression from this post (Regular expression for extracting tag attributes). (\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>"\']))+.)["\']? I've created the following PHP code and it works nicely. I get [id='gridview1' and 'id' and 'gridview1'] from the preg_match_all() function. $regexp = '/(\S+)=["\']?...

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

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...

Extract keywords/tags from string using Preg_match_all

I have the following code $str = "keyword keyword 'keyword 1 and keyword 2' another 'one more'".'"another keyword" yes,one,two'; preg_match_all('/"[^"]+"|[^"\' ,]+|\'[^\']+\'/',$str,$matches); echo "<pre>"; print_r($matches); echo "</pre>"; Where I want it to extract keywords from a string, and keep those wrapped within single or do...

Why am I getting empty results in my RegExp?

I am trying to parse my URL into different parts using this RegExp: ([\w\\.-]*) Given an example URL http://www.foo.com/bar/baz I get those results from preg_match_all(): Array ( [0] => Array ( [0] => http [1] => [2] => [3] => [4] => www.foo.com [5] => [6] => bar ...

Regex to match string between %

I'm trying to match substrings that are enclosed in %'s but preg_match_all seems to include several at the same time in the same line. Code looks like this: preg_match_all("/%.*%/", "%hey%_thereyou're_a%rockstar%\nyo%there%", $matches); print_r($matches); Which produces the following output. Array ( [0] => Array ( ...

preg_match in preg_match_all

$match_expression = '/<a href="look.php\?id=(.*)" title="Look page: (.*)">(.*)<\/A>/'; $radompgr = preg_match_all($match_expression,$q2,$match, PREG_SET_ORDER); if($radompgr == TRUE){echo "found $radompgr<br>";}else{echo "not found $radompgr<br>";} //found for ($i = 0; $i < count($match); $i++) { $mathcas = $match[$i][1]; $rado...

RegEx problem - retrieve content of tag with given class - preg_match(_all)

Hi, I need to retrieve content of <p> tag with given class. Class could be simplecomment or comment ... So I wrote the following code preg_match("|(<p class=\"(simple)?comment(.*)?\">)(.*)<\/p>|ism", $fcon, $desc); Unfortunately, it returns nothing. However if I remove tag-ending part (<\/p>) it works somehow, returing the string wh...

Regular expression to put <P> AND <ul>/<ol> into array

I'm searching for a function in PHP to put every paragraph element like <p>, <ul> and <ol> into an array. So that i can manipulate the paragraph, like displayen the first two paragraphs and hiding the others. This function does the trick for the p-element. How can i adjust the regexp to also match the ul and ol? My tryout gives an err...

preg_match_all [200932]

Hello everyone i want to preg_match [200932] this from a string. I tryied some pattern but didnt help, any idea? ...

Regular Expression vs XML Functions in PHP

Hiya, I currently do alot of data parsing, and have toyed with PHP functions for XML such as simple XML and a few others here and there. But there always seems to be some sort of issue with dealing with them, mainly due to the way the data is presented. The most reliable way i have found is to always just simply use preg_match_all a...

How can I find all matches of '{{**** *** **}}' with a regex?

I'm trying to extend PHP Markdown to allow the use of {{ and }} around some parts of the text (they will become search keywords, like a tag). I have this basic regex that kinda works: preg_match_all("/\{\{(.*)\}\}/", $description, $nomsTags); Except it doesn't work when there are 2 keywords in the same sentence: This {{is}} just an ...

How can I find all matches of <element>something</element> with a regex?

So let's say that I have: <any_html_element>maybe some whitespaces <br/>Some text</any_html_element> And I want to remove the first <br/> after <any_html_element>. How can I do that? Best Regards ...

preg_match Vs preg_match_all browser error not php?

Hi all i have the following: $str = base64_encode(preg_replace("#\s|\r|\t|\n#", " ", file_get_contents("../www.cms.actwebdesigns.co.uk2/logged.php"))); if(preg_replace("#(PD9waHAg)((?!(Pz4g)).)*#is", $str, )) { #print_r($matches); echo "<xmp>".base64_decode($matches[0]."Pz4g")."</xmp>"; } now this works but i want to be able t...

preg_match_all print *all* matches

Hy guys! I need to print all matches using preg_match_all. $search = preg_match_all($pattern, $string, $matches); foreach ($matches as $match) { echo $match[0]; echo $match[1]; echo $match[...]; } The problem is I don't know how many matches there in my string, and even if I knew and if it was 1000 that would be pretty d...

Yet Another Regular Expression

Is there a way to tell preg_match_all to use the third match it finds skipping the first two? For example, I have the following HTML <div class="entry"> <div class="text">BlaBlaBla</div> <div class="date">2009-10-31</div> </div> I need preg_match_all to get the contents of the outermost div, and not stop at the first /div it e...

How to retrive number with prep_match_all()

Hi, Inside my webpage "http://www.my_web_page" I have something like that: img border="0" class="borderx" id="pic_15132" I wanna know which parameter did I have to use inside preg_match_all("") to retrive only the number. Here is what I tried but my result is: _15132 $webpage = file_get_contents("http://www.my_web_page"); pre...

Using regex variables in preg_match_all

Hi, I'm building a pseudo-variable parser in PHP to allow clean and simple syntax in views, and have implemented an engine for if-statements. Now I want to be able to use nested if-statements and the simplest, most elegant solution I thought of was to use identation as the marker for a block. So this is basicly the layout I'm looking f...