preg-match-all

preg_match_all Problems

Hello, I'm trying to match a string that contains HTML code that contains parameters to a function in Javascript. There are several of these functions found in the the string containing the HTML code. changeImg('location','size'); Let's say that I want to grab the location within the single quotes, how would I go about doing this? T...

PHP preg_match_all help

Hey guys. I am trying to match the FDSize: in the following: Gid: 48 48 48 48 FDSize: 64 Groups: 48 425 VmPeak: 289928 kB It comes from /proc/status is not fixied length, and neither is the lines above or below. Can any one help? Thanks ...

How do I use preg_match_all with 2 values and preg_replace to create 2 different links

I have a text file that I am displaying in a table. I am using preg_match_all to find a specific Title with a specific Chapter and I am replacing the Title and Chapter with preg_replace to make it a link.. For example the contents within the text file are as follows: Dec 04 20:15 Naruto 123 Dec 04 17:42 Naruto 98 Dec 04 16:19 D Gray Ma...

PHP RegularExpression : match anything (including whitespaces)

text text text text text text {test} content content content {/test} text text text text text text i need to get two separate results from the above string: 1. {test} content content content {/test} 2. content content content so, what should be the two separate regular expression patterns for...

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

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

Regex Pattern for findin http in PHP

Hello everyone, how can i extract the http from this text? "Text: Here's 2 free bonuses. http://blablabla.blabla/blabla " But the url can also be another one. Finaly After i have the array, wich contains usualy just one url, how can i add it to the above text exactly at the same position? but with html tag <a> the results should l...

PHP PREG Question

As hard as I try, PREG and I don't get along, so, I am hoping one of you PHP gurus can help out .. I have some HTML source code coming in to a PHP script, and I need specific items stripped out/removed from the source code. First, if this comes in as part of HTML (could be multiple instances): <SPAN class=placeholder title="" jQuery12...

Matching usernames in a memberlist using regex

On a phpBB forum, memberlist.php lists all the members of the board with the following HTML: <a href="profile.php?mode=viewprofile&amp;u=4">Username</a> Where u=4 is the UserID of the user, and Username is obviously their username. There are probably 50-100 peices of HTML like this and I would like to match them all, so I was going t...

preg_replace inside of preg_match_all problems

I'm trying to find some certain blocks in my data file and replace something inside of them. After that put the whole thing (with replaced data) into a new file. My code at the moment looks like this: $content = file_get_contents('file.ext', true); //find certain pattern blocks first preg_match_all('/regexp/su', $content, $matches); f...

Preg_match_all: Regex to extract block of data

Would somebody care to help me out with a preg_match_all Regex? I need to extract from a block that looks like this: (arbitrary data) alt=BAUSTEIN^550^^transparent^transparent^null^null^(...base64 encoded data...) ^ (arbitrary data) alt=BAUSTEIN^550^^transparent^transparent^null^null^(...base64 encoded data...) ^ all base64 encoded b...

What am I doing wrong with preg_match_all?

The object is to find sets such as <!-- content:start -->some content here<!-- content:stop --> and process each one to put it into an array, but every time it find no matches and echos my die statement without printing any matches out. This is the current function that is being executed. function boom($data) { $number = preg_match_...

preg_match_all ensure distinct/unique results

Hi I am using the following code to match all variables in a script starting with '$', however i would like the results to not contain duplicates, ie be distinct/unique: preg_match_all('/\$[a-zA-Z0-9]+/', $code, $variables); Any advice? ...

[PHP] preg_match_all crashing/bugging?

Okay, so I have this script that has been the same for at least 3 months now. The code hasn't been modified at all. Nor has my server (VPS) been modified either. But now out of nowhere, started about 24 hours ago, a line in the script is causing the page/script to timeout/crash (white page after about 30 seconds). The line of code in qu...

URL matching using preg_match_all in PHP and regex

I am trying to build a crawler that gets the movie urls from an imdb list. I am able to get all the links on the page into an array and want to select only those ones with "title" in them. preg_match_all($pattern, "[125] => href=\"/chart/2000s?mode=popular\" [126] => href=\"/title/tt0111161/\" ", $matches); where $pattern='/title/'. ...

PCRE: Lazy and Greedy at the same time (Possessive Quantifiers)

I am trying to match a series of text strings with PCRE on PHP, and am having trouble getting all the matches in between the first and second. If anyone wonders why on Earth I would want to do this, it's because of Doc Comments. Oh, how I wish Zend would make native/plugin functions to read Doc Comments from a PHP file... The following...

Regex Expert - PHP Lookaround

Hi all, I am absolutely useless at regular expressions, so i'd appreciate your help. I have a string, such as this: $foo = 'Hello __("How are you") I am __("very good thank you")' I know it's a strange string, but stay with me please :P I need a regex expression that will look for the content between __("Look for content here") and...

PHP: How do I get the string indexes of a preg_match_all?

Hi all, let's say I have two regexp's, /eat (apple|pear)/ /I like/ and text "I like to eat apples on a rainy day, but on sunny days, I like to eat pears." What I want is to get the following indexes with preg_match: match: 0,5 (I like) match: 10,19 (eat apples) match: 57,62 (I like) match: 67,75 (eat pears) Is there any way to ...

Find everthing that is not between specific tags

Hi, i'm using preg_match_all('/<?(.*)?>/', $bigString, $matches, PREG_OFFSET_CAPTURE); to find the contents of everything between <? and ?> Now I'd like to find everything that is NOT between <? and ?> I'm trying with preg_match_all('/^(<?(.*)?>)/', $bigString, $nonmatches, PREG_OFFSET_CAPTURE); but that doesn't seem to work... ...

How do I process the largest match first in PHP?

Ok, so I tried searching around first but I didn't exactly know how to word this question or a search phrase. Let me explain. I have data that looks like this: <!-- data:start --> <!-- 0:start --> <!-- 0:start -->0,9<!-- 0:stop --> <!-- 1:start -->0,0<!-- 1:stop --> <!-- 2:start -->9,0<!-- 2:stop --> ...

PHP regex help with preg_match_all

Hi, I am trying to refine a preg_match_all by finding the second occurrence of a period then a space: <?php $str = "East Winds 20 knots. Gusts to 25 knots. Waters a moderate chop. Slight chance of showers."; preg_match_all ('/(^)((.|\n)+?)(\.\s{2})/',$str, $matches); $dataarray=$matches[2]; foreach ($dataarray as $value) { echo $val...