preg-match

Regular Expression Question

I have a regular expression in PHP that looks for the date in the format of YYYY-MM-DD What I have is: [\d]{4}-[\d]{2}-[\d]{2} I'm using preg_match to test the date, the problem is that 2009-11-10 works, but 2009-11-1033434 works as well. It's been awhile since I've done regex, how do I ensure that it stops at the correct spot? I've ...

Ignore data within a certain set of characters with PHP

Not sure what this is called, but is there a way I can pull data from a file, echo it, but ignore data within a certain set of characters? <?php echo file_get_contents('test.txt'); ?> Would it be possible to ignore the data in between the asterisks, and the asterisks themselves when I echo out the final function? ...

PHP,preg_match,Regular Expression. What am I doing wrong?

Here is the pattern that I want to match: <div class="class"> <a href="http://www.example.com/something"&gt; I want to be able to capture this text</a> <span class="ptBrand"> This is what I am doing: $pattern='{<div class="productTitle">[\n]<((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)>([...

Checking a string against a pattern

I want to check posted content against a pattern. I am having trouble setting up this preg_match (or array?). The pattern being... TEXTHERE:TEXTHERE TEST:TEST FILE:FILE AND TEXTHERE:TEXTHERE TEST:TEST FILE:FILE I want to check for either pattern, the one with the whitespace and the one with the line break. If the posted content is...

Php preg_match help

I am trying to find a php preg_match that can match test1 test2[...] but not test1 test2 [...] and return test2(...) as the output as $match. I tried preg_match('/^[a-zA-Z0-9][\[](.*)[\]]$/i',"test1 test2[...]", $matches); But it matches both cases and return the full sentence. Any help appreciated. ...

Are the PHP preg_functions multibyte safe?

There are no multibyte 'preg' functions available in PHP, so does that mean the default preg_functions are all mb safe? Couldn't find any mention in the php documentation. ...

PHP Multiple digits regular expression

I need to extract the digits from the following string using regular expression: pc 32444 xbox 43567 so my array will be array ([0] => 32444 [1] => 43567) Can someone help construct a preg_match for me? Thanks! ...

preg_match returning weird results

I am searching a string for urls...and my preg_match is giving me an incorrect amount of matches for my demo string. String: Hey there, come check out my site at www.example.com Function: preg_match("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", $string, $links); echo count($links); The result comes out as 3. Can anybody help...

PHP Regular Expression [accept selected characters only]

I want to accept a list of character as input from the user and reject the rest. I can accept a formatted string or find if a character/string is missing. But how I can accept only a set of character while reject all other characters. I would like to use preg_match to do this. e.g. Allowable characters are: a..z, A..Z, -, ’ ‘ User must ...

using regex to get extract username from email address

My string of text looks like this [email protected] (John Doe) I need to get just the part before the @ and nothing else. The text is coming from a simple xml object if that matters any. The code i ahve looks like this $authorpre = $key->{"author"}; $re1='((?:[a-z][a-z]+))'; if ($c=preg_match_all ("/".$re1."/is", $authorpre, $matc...

How do I look for “ and ” in php using preg_match?

I've been using "/x{201C}/u" and "/x{201D}/u" to match them, but there's no result. Am I doing something wrong?? ...

Get keyword from a (search engine) referrer url using PHP

Hi, I am trying to get the search keyword from a referrer url. Currently, I am using the following code for Google urls. But sometimes it is not working... $query_get = "(q|p)"; $referrer = "http://www.google.com/search?hl=en&amp;q=learn+php+2&amp;client=firefox"; preg_match('/[?&]'.$query_get.'=(.*?)[&]/',$referrer,$search_keyword); ...

Preg Match Empty String

How to preg_match for an null (empty) string?? I need something like: /([0-9]|[NULL STRING])/ ...

Only execute script if entered email is from a specific domain

I am trying to create a script that will only execute its actions if the email address the user enters is from a specific domain. I created a regex that seems to work when testing it via regex utility, but when its used in my PHP script, it tells me that valid emails are invalid. In this case, I want any email that is from @secondgear...

Preg matching and counting the resulting match in a short string

I already have a function that counts the number of items in a string ($paragraph) and tells me how many characters the result is, ie tsp and tbsp present is 7, I can use this to work out the percentage of that string is. I need to reinforce this with preg_match because 10tsp should count as 5. $characters = strlen($paragraph); $items ...

With PHP how do you output a textfile into a table along with links.

I have this text file: Dec 04 20:15 Naruto 123 Dec 04 17:42 Naruto 98 Dec 04 16:19 D Gray Man 001 Dec 04 16:05 Bleach 128 Dec 04 12:13 50 x 50 44 I need to output the contents into a table with the Date and Time in its own column and the Tile and Chapter in another. Also.. I need to replace the Title and Chapter with a link that must...

Another tricky preg_match

Just need to see if a paragraph contains a "stop word", the stop words are in an array below. I had the formula as: $pattern_array = array("preheat", "minutes", "stir", "heat", "put", "beat", "bowl", "pan"); foreach ($pattern_array as $pattern) { if (preg_match('/'.$pattern.')/i', $paragraph)) { $stopwords = 1; ...

With PHP filter a textfile into an A-Z listing

I have a text file that reads: 9123 Bellvue Court 5931 Walnut Creek rd. Andrew Bailey Chris Drew Earl Fred Gerald Henry Ida Jake Koman Larry Manny Nomar Omar Perry Quest Raphael State Telleman Uruvian Vixan Whales Xavier Yellow Zebra What I need to do is I need to create a A-Z listing... so: # A B C D E F G H I J K L M N O P Q R S T ...

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

How do I preg_match for words in Hebrew.

Hey, I need a function that matches full words in hebrew in php. Please help. ...