preg-match-all

php preg_match_all, regex, extract specific value

I'm trying to extract the users who ask questions on a classified ad website(http://trademe.co.nz/Trade-Me-Motors/Cars/Toyota/Hiace/auction-300294634.htm) . For some reasons the pattern which I'm using is not working always so I would appreciate if you will help me with a perfect regex Here is my current code /get memberid of the que...

preg_match expression help

Can't seem to figure this one out. Just trying to preg match for a specific variable name in a link URL: <a href="http://something.com?variable=name"&gt;GenericLink&lt;/a&gt; How do I get the variable=name out of this? Thanks! ...

Why does preg_match_all poop out after so many characters?

I'm having a problem with my preg_match_all statement. It's been working perfectly as I've been typing out an article but all of a sudden after it passed a certain length is stopped working all together. Is this a known issue with the function that it just doesn't do anything after so many characters? $number = preg_match_all("/(<!-- ([...

preg_match_all: Why would "this" match but "that" won't?

So, I'm basically trying to match anything inside (and including) object tags, with this: <?php preg_match_all('/<object(.*)<\/object>/', $blah, $blahBlah); ?> It finds a match for this: <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="250" codebase="http://download.macromedia.com/pub/shockwave/cabs/fl...

Regex - Grab a specific word within specific tags

Hey guys, I don't consider myself a PHP "noob", but regular expressions are still new to me. I'm doing a CURL where I receive a list of comments. Every comment has this HTML structure: <div class="comment-text">the comment</div> What I want is simple: I want to get, from a preg_match_all, the comments that have the word "cool" in th...

How to extract multiple patterns from txt doc.

I have a text document that lists urls with their subject and an email address. I need to extract all urls with their subject and the email address and put this all into a csv file. I just need to know how I can use regex to do this. Currently I am able to extract all urls but I need the email and subject associated with them. This is wh...

Assign regex pattern as key to an array.

I have an array of regular expressions and am trying to loop through a text document to find the first pattern, assign that as the key to an array then continue through find the second pattern and assign that as the value. Whenever I come across pattern 1 I want that to always be assigned as a key and all pattern 2 matches that follow un...

regular expression anchor tag

hi to all i am using php and i am having problem to parse the href from anchor tag with text. example: anchor tag having test http://www.test.com like this <a href="http://www.test.com" title="test">http://www.test.com&lt;/a&gt; i want to match all text in anchor tag thanks in advance. ...

Stop a regex matching *everything* after what I want to actually match!

Hey! I am quite new to the whole Regex thing and tried to do a preg_match_all in PHP which, kind of the results I wanted but the problem is it matches everything after what I actually wanted... like so: String: This is something <code>Some code here</code> and more Match from Regex: <code>Some code here</code> and more Wanted match fro...

can anybody explain ther 4 lines of php code I am so confused.

code- $res=$this->post("http://address.mail.yahoo.com/?_src=&amp;VPC=print",$post_elements); $emailA=array(); $bulk=array(); $res=str_replace(array(' ',' ',PHP_EOL,"\n","\r\n"),array('','','','',''),$res); preg_match_all("#\<tr class\=\"phead\"\>\<td colspan\=\"2\"\>(.+)\<\/tr\>(.+)\<div class\=\"first\"\>\<\/div\>\<...

how to match whole html elements no matter what is inside just as browsers do it ?

on a given page there are bunch of elements: <div class="some class"> <-- here is anything, other divs, even other divs with the same class, but I need to match right on closing tag for this particular opening tag --></div> ...

Finding correct php regex for this complex element

Hi since hours im trying to get a regex which is able to find the following part in a string. [TABLE|head,border|{ #TEXT|TEXT|TEXT# TEXT|TEXT|TEXT TEXT|TEXT|TEXT TEXT|TEXT|TEXT }] Its from a simple self made WYSIWYG Editor, which gives the possibility to add tables. But the "syntax" for a table should be as simple as the one above. N...

PHP Regex for splitting a string at the first occurrence of a character.

This may be a lame question but I am a total novice with regular expressions. I have some text data in the format: Company Name: Name of the company, place. Company Address: Some, address, here. Link: http://www.somelink.com Now, I want to use a regex to split these into an array of name : value pairs. The regular expression...

preg_match_all returning only one match

Hi, I'm a PHP newbie. I'm trying to use preg_match_all function in the below program to find all subjects with their marks, but I'm getting only one match. I have been struggling with this for 5 hours. Can someone help me in figuring out whats wrong? Thanks in advance. <?php $semArray="<B>STUDENTS NAME (7ab05cs001) </B><br><br><br><br>...

Regular expression for ignoring an optional comma

I have a text: $test = <<<START DOTHIS themsp1 @theint = 431, @theText = "%dumdum%", @operator = 'ANY', @crossCheck = 'PLUS' START; The filter: $regEx = '/@(.*)=(.*)[,]*?/'; preg_match_all($regEx,$test,$vars,PREG_SET_ORDER); print_r($vars); The Output: Array ( [0] => Array ( [0] => @theint ...

regex matching multiple values when they might not exist

I am trying to right a preg_match_all to match horse race distance. My source lists races as: xmxfxy I want to match the m value, the f value, the y value. However different races will maybe only have m, or f, or y, or two of them or even all three. // e.g. $raw = 5f213y; preg_match_all('/(\d{1,})m|(\d{1,})f|(\d{1,})y/', $raw, $distan...

Regex find specific tags for replace in a string

Hello all, I have a string with some codes (ex:«USER_ID#USERNAME#STATUS») for replacement like in this example: Hello «USER_ID#USERNAME#STATUS», do you like «PROD_ID#PRODNAME#STATUS»? I need to find a way to get all the codes for future replacement. I can easily find one code with this regex: /«(.*)#(.*)#(.*)»/ but can't f...

"Unknown modifier 'g' in..." when using preg_match in PHP?

This is the regex i'm trying to use: /^(\w|\.|-)+?@(\w|-)+?\.\w{2,4}($|\.\w{2,4})$/gim I found it on this site, and it works great when i try it out there. But as soon as i place it in my code i get this message: Warning: preg_match() [function.preg-match]: Unknown modifier 'g' in C:\xampp\htdocs\swebook\includes\classes.php on line ...

Preg match all greedy with exception for string

My source string is this: {categories group_id="3"} {category_name} {/categories} {categories group_id="4"} {category_name} {/categories} My regex is this: preg_match('/{categories group_id="3"}(.*){\/categories}/s', $tagdata, $matches); Which results in: Array ( [0] => Array ( [0] => {categories group_id=...

Regular Expressions: get what is outside of the brackets

I'm using PHP and I have text like: first [abc] middle [xyz] last I need to get what's inside and outside of the brackets. Searching in StackOverflow I found a pattern to get what's inside: preg_match_all('/\[.*?\]/', $m, $s) Now I'd like to know the pattern to get what's outside. Regards! ...