preg-match

php preg_match tab separated

I need a regular expression to look for the first N chars on an array until a tab or comma separation is found. array look like: array ( 0 => '001,Foo,Bar', 1 => '0003,Foo,Bar', 2 => '3000,Foo,Bar', 3 => '3333433,Foo,Bar', ) I'm looking for the first N chars, so for instance, pattern to search is 0003, get array index 1... ...

regex: converting php code from eregi to preg_match

Hi. I'm trying to find the proper regular expression to convert eregi($1,$2) to preg_match("/$1/i",$2) i need to consider if there will be functions with () in it, and they may appear more then once. can anyone please provide the proper regular expression to do so ? thanks ...

Only match word outside a HTML statement with a regex

The thing I want to achieve with the code below: match a specified word case-insensitive and only once in a text and replace it with a link. I have the following preg_match to match the word 'foo' in a string: if (preg_match("/\bfoo\b/i", $text, $results, PREG_OFFSET_CAPTURE)) { // substr_replace the word 'foo' for a link <a href.. ...

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

Problem with MySQL storage of a Craigslist parse

I'm using MagpieRSS to parse a Craigslist feed. The "title" field is: ***BUYING ALL BRAND NEW BLACKBERRY IN ANY QUANTITY BOLD~JAVELLIN~ONYX (Gramercy) $100000 and I'm using if( preg_match( "/\(*\)*\d+$/", $title, $matches ) ) to figure out the price. $matches[0] should have the price, if I'm not mistaken. However, when I put ...

How can I match ALL terms using Regular Expressions in PHP?

I figured out how to check an OR case, preg_match( "/(word1|word2|word3)/i", $string );. What I can't figure out is how to match an AND case. I want to check that the string contains ALL the terms (case-insensitive). ...

Regular Expression for Mathematic Equations in PHP

Hi everyone. I am trying to create a regular expression that understands mathematical equations (>, <, =, <=, >=, !=). Which is something pretty simple. I have come up with: /(.*)([!<>][=]|[<>=])(.*)/ But when I use this regex in PHP, with preg_match, if equation is XYZ!=ABC, it just matches with =. Shouldn't it match the first expr...

Javascript match doesn't work in IE

I have the following code. function rgb2hex(rgb) { rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } Seems to work ok in FF and Chrome. IE comes up with '1' is null or not an object. rgb value does seem to make it to the rgb.match. Any ideas? Thx ...

How to get rid of ® and ™ in the string? (PHP)

Hello! I have a string like "Welcome to McDonalds®: I'm loving it™"... I want to get rid of ":", "'", ® and ™ symbols, so I do the following: $string = "Welcome to McDonalds®: I'm loving it™"; $string = preg_replace('/[^a-zA-Z0-9 -]/', '', $string); BUT on the output I receive: "Welcome to McDonaldsreg Im loving ittrade"... so preg...

Parsing content in html tags using regex

Hi I want to parse content from <td>content</td> and <td *?*>content</td> and <td *specific td class*>content</td> How can i make this with regex, php and preg match? ...

Replace text between @import and \n with preg_replace (PHP)?

I use PHP. I'm working on a way to automatically put together all my CSS files into one. I automatically load the CSS-files and then saves them to a larger one, for upload. In my local installation I have some @import lines that needs to be removed. It looks like this: @import url('css/reset.css'); @import url('css/grid.css'); @impor...

Url Matching using Gruber's regex in PHP

how do I get the regex mentioned in this article working with preg_match in php? <?php preg_match("\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))/i", $text, $matches); print_r($matches); ?> Using the code above I get the following error: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanume...

PHP preg_match to find multiple occurrences

What is the correct syntax for a regular expression to find multiple occurrences of the same string with preg_match in PHP? For example find if the following string occurs TWICE in the following paragraph: $string = "/brown fox jumped [0-9]/"; $paragraph = "The brown fox jumped 1 time over the fence. The green fox did not. Then the br...

preg_match for sentences begining with 'for the'....

Pretty simple but I cant get the exact syntax working. I just want a true or false check to see if a string beings with 'for the' (case insensitive). Thanks everyone. ...

PHP Regular expression, how to match the first section which includes a [ symbol?

Hi Guys ive tried to search for this answer all morning, but with no luck, all i want to do is match [slideshow or [gallery with the included [ bracket.. code as follows. $gallery = get_post_meta($post->ID, 'gallery', true); if (preg_match("|^/[slideshow", $gallery)) { echo "Slideshow was forund"; } else if (preg_match("|^/[ngga...

How to extract Heading tags in PHP from string

Hello everyone, From a string that contains a lot of HTMl, how can I extract all the text from <h1><h2>etc tags into a new variable. Possibly using preg_match_all and sending the matches to a single comma delimited variable. Thanks guys. ...

Filename regex extraction

Hi, I'd like to get parts of the filename filenameblabla_2009-001_name_surname-name_surname I'd like to get: 2009-001, name_surname, name_surname I've come up with this, but it's no good preg_match("/(?:[0-9-]{8})_(?:[a-z_]+)-(?:[a-z_]+)/", $filename, $matches); Any pointers? Thanks! BR ...

Getting contents of square brackets, avoiding nested brackets

(first time poster, long time visitor via Google) I'm trying to extract the contents of some square brackets, however i'm having a spot of bother. I've got it working for round brackets as seen below, but I can't see how it should be modified to work for square brackets. I would have thought replacing the round for square and vice versa...

Any preg_match to check if a url is a youtube/vimeo/dailymotion video link ?

What's the best preg_match syntax to check if a url is a video link of youtube/vimeo/ or dailymotion? maybe if it's hard, then just to check the domain name. Thanks ...

Check SQL statements within PHP for bad words such as DROP or DELETE

Hi! I would like to allow some admins to manually enter SQL statements in a textfield (to get statistic data etc.). On the database layer, I protected the data by creating a user which can only select but not update/delete etc. I would like to add a second security by checking the inserted SQL for bad words such as DROP, DELETE or UPDA...