preg-match

"string" != "string"

Hi. I'm doing some kind of own templates system. I want to change <title>{site('title')}</title> Into function "site" execution with parameter "title". Here's private function replaceFunc($subject) { foreach($this->func as $t) { $args = explode(", ", preg_replace('/\{'.$t.'\(\'([a-zA-Z,]+)\'\)\}/', '$1', $subject)); ...

A maximum character limit on the preg functions?

On my site I use output buffering to grab all the output and then run it through a process function before sending it out to the browser (I don't replace anything, just break it into more manageable pieces). In this particular case, there is a massive amount of output because it is listing out a label for every country in the database (a...

preg_match for <?php, <?, and/or ?>

Hello guys, I'm not very familiar with regEx's and I'm trying to find a preg_match regex for searching for any of the following strings within a file and if found it will halt it. I already have the fopen and fgets and fclose setup I just need to use a regex inside of a preg_match for the following php tags: <?php <? ?> so if preg_mat...

PHP get url out of a string and some more...

Hello, I have a string like this The theme song of whatever - http://www.anydomain.com/pop_new.php?sid=10623&amp;aid=1581&amp;rand=0.6808111508818073 #string And now, I need to do the following thing. Get the url from above string http://www.anydomain.com/pop_new.php?sid=10623&amp;aid=1581&amp;rand=0.6808111508818073 Replace the url ...

I need a regex to return true for 01.mp4

I want to sort out specific files depending on their names, i want a regex that returns true for file names like : 01.mp4, 99.avi, 05.mpg. the file extensions must match exactly to the ones that i want and the filename must start with characters which can not be longer than 2 characters. the first part is done but the file extensions ar...

PHP preg_match: a pattern which satisfies all MySQL field names (including 'table.field' formations)

i need a pattern which satisfies mysql field names, but also with the option of having a table name before it examples: mytable.myfield myfield my4732894__7289FiEld here's what i tried: $pattern = "/^[a-zA-Z0-9_]*?[\.[a-zA-Z0-9_]]?$/"; this worked for what i needed before, which was just the field name: $pattern = "/^[a-zA-Z0-9_]...

preg_match and long strings

Hi, This is the preg_match i am trying to use to find specific text in text file. if (preg_match($regexp,$textFile,$result) > 0) { echo "Found ".$result[0]; } else { echo "Not found"; } However, the result is always Found and nothing more. The result array is empty. Now i read that preg_match can't work with long strings. My...

How to validate a domain name using Regex & Php?

Hi, I want a solution to validate only domain names not full urls, The following example is what i'm looking for: domain.com -> true domain.net/org/biz... -> true domain.co.uk -> true sub.domain.com -> true domain.com/folder -> false domµ*$ain.com -> false Thank you ...

PHP regular expression for positive number with 0 or 2 decimal places

Hi I am trying to use the following regular expression to check whether a string is a positive number with either zero decimal places, or 2: ^\d+(\.(\d{2}))?$ When I try to match this using preg_match, I get the error: Warning: preg_match(): No ending delimiter '^' found in /Library/WebServer/Documents/lib/forms.php on line 862 ...

php preg_match pattern to extract a specific information, regex

I need to extract a specific Id from a html document but the problem is that the id must not "be used". Here is the html content http://pastebin.com/wF2dx8JZ As you may see there are different html blocks . Some of them contain the "Used" word so I need to extract only the first id which is not used. Basically I can write a simple p...

regex , php, preg_match

I'm trying to extract the mileage value from different ebay pages but I'm stuck as there seem to be too many patterns because the pages are a bit different . Therefore I would like to know if you can help me with a better pattern . Some examples of items are the following : http://cgi.ebay.com/ebaymotors/1971-Chevy-C10-Shortbed-Truck-/25...

PHP strpos preg_match

Hi, I want to copy a substring of a string using PHP. The regex for the first pattern is /\d\|\d\w0:/ The regex for the second pattern is: /\d\w\w\d+:\s-\s:/ Is it possible combining preg_match with strpos to get the exact positions from start to end and then copy it with substr( $string, $firstPos,$secPos ) ? ...

what is the regular expression for this

I want to parse this (adv) much (thanks) I want to eliminate the words and the bracket (adv) but not (thanks) the condition is: inside bracket, and word length inside bracket is 1-5 characters I am using preg_match in PHP Thank You ...

php 5.3, regex to get specific data from a string based on preceding text and <br>

hi, I have the following string example: PASSWORD = dsl3£$Roid dfdfdf fgdgfdfg fgdfgdfg dfgdfg dfgdfgdfg its stored in MySql Text field. I need to get the "password" ie dsl3£$Roid Its preceded by PASSWORD = and there is a \n line break after. I can use nl2br to make the string like this: PASSWORD = dsl3£$Roid<br> dfdfdf<br> fgdgfd...

PHP preg_match: escaping { and }

Hello. I am facing a little problem. My string is From {start} to {end} and I want to validate it using preg_match() to avoid illegal chars. preg_match("/^[a-zA-Z\{\} ]{1,}$/",$var) The point is the escape for { and }. thanks :) ...

regex help please

Hello Guys need a quick Regular expression to match the following A-Z a-z 0-9 " - ? . ', ! new lines and spaces Any ideas? ...

Need help with really simple regular expression

I am using PHP to match the following data type : [["1200","135"],["127","13"]] I want to extract all the numbers into a seperate array of arrays like this : array(array(1200,135),array(127,13)); I am using preg_match to capture the elements but so far i am not even able to match them against a rule. I will gladly appreciate if som...

Using preg_match to get filename

We use custom bbcode in our news posts [newsImage]imageName.jpg[/newsImage] And i'd like to use preg_match to get the imageName.jpg from between those tags. The whole post is stored in a variable called $newsPost. I'm new to regex and I just can't figure out the right expression to use in preg_match to get what I want. Any help is ap...

Preg_match help for finding count

HI all i have a string <font size="+1"><b>Open Directory Sites</b></font> (1-20 of 10000)<p> i need to get 10000 as answer .. how i use preg_match ??? Note: this is implortant that the multiple occurance of match Thanks in advance ...

Regular expression help in PHP

I'm currently trying to learn regular expressions with some simple "real world" examples. Take in consideration the following string: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2a1pre) Gecko I want to find the RV value (1.9.2a1pre). I need to apply the following rules: RV: can be in any case (RV, rv, rV, Rv...). RV...