preg-match

preg_match url get parameter parsing

Hi! I am trying to extract the latitude and longitude of a google maps url. Such an url could look like this: $url = 'http://maps.google.com/?ie=UTF8&ll=39.811856,11.309322&spn=0,0.485802&t=h&z=12&layer=c&cbll=39.311856,11.519322&panoid=1hltSSOoqv5H1dVKZWFkaA&cbp=13,117.95,,1,16.71'; As you can see, ther...

Help with Regex using preg_match

Hi, Recently i've switched to PHP 5.3+ and after that migration i learned that the eregi() function has been depreciated, its the function i mostly used for my regex needs. But now i had to switch to preg_match() function, i am having trouble validating a certain condition. Hello World I want the preg_match to validate the above "hel...

preg_match a part of an HTML file : find X and (maybe X or not) until the end of HTML file

Hi to all, This is driving me nuts! A little piece of code that I can't seem to debug :( Basically I have an HTML file in a string and I want to find X inside until another X (same value) IF there is another one, if there isn't, then grab X until end of file. The code that doesn't work: $contents = "< div id="main" class="clearfix"> ...

get the content of matched element

i have a string $str = "this is [start] my string [end] at this moment"; i need to get the content within [start] and [end]. when i use $result = preg_match('/\[start\].+\[end\]/',$str, $m); it mutches [start] my string [end], but i need to get only my string(without spaces). sure i can make another preg_replace and delete the...

preg_match to domain.tld

Hi, How can i get the strings that only contains domain.tld? if (preg_match('^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$', $domain)) echo "domain.tld found!"; but for the regex ^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$, sub domains are also okay. But i just want to check "domain.tld". What regex should i use for it? Thank you. ...

Unknown modifier '/' in ...? what is it?

When i wrote the following, i get such warning, and it doesn't match anything, but i'm sure, that $row_search['content'] contains $value... preg_match_all("/[^\s]*".preg_quote($value)."[^\s]*/iu", $row_search['content'], $final_matched); WARNING:preg_match_all() [function.preg-match-all]: Unknown modifier '/' in C:\xampp\htdocs\finance...

PHP - Regular Expressions Help Needed

I got a contact form, I need to filter some words. I'm doing it as following: $array = array('lorem', 'ipsum', 'ip.sum'); for($i = 0; $i < count($array); $i++) { if( preg_match("/".$array[$i]."/", (string) $field) ) { return false; } } I'm not a regex master, but it ...

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

Regular Expressions: low-caps, dots, zero spaces

hi, how do I write an expression which checks for lowcaps, dots, and without any white space in the string? the code below so far was trying to check for lowcaps and dots (it does not work anyway!) but I don't know how to add in the expression for white spaces. # check for matches of lowcaps or lowcaps with a dot if (!preg_match('/([a...

PHP email validation

For PHP what is the best email validation using preg, NOT ereg because it's deprecated/removed. I don't need to check if the website exists (it's not like maximum security). I've found many ways with ereg but they (obviously) aren't good practice. ...

PHP - preg_match() and eregi() not working?

Hey there! I'm having a bit of a problem trying to validate email adresses using preg_match (or eregi() if that suits better). I've tried several regex patterns now and no matter what i do it doesn't seem to work. Here's the function: function validateEmail($email) { if(eregi('[a-z||0-9]@[a-z||0-9].[a-z]', $email)){ retur...

preg_match cannot find backslash

preg_match(”[\\]“, $somedatawithbackslash); throws exception: Warning: preg_match() [function.preg-match]: No ending matching delimiter \’]\’ found preg_match(’/\\\\/’, $somedatawithbackslash); throws exception: Warning: preg_match() [function.preg-match]: No ending matching delimiter \’]\’ found preg_match('#\\#, $somedatawithbackslas...

using php preg_match

Hi-- I am trying to use PHP preg_math parse a string that looks like: 6.15608128 Norwegian kroner I just want the first part (the digits), not the text. I wrote a simple regex like [0-9\.]+ that works fine in regex testers, but PHP complains about the '+'. Can anyone help me write this regex so it's valid for the preg_match funct...

regular expression to detect numbers written as words - UTF-8 input

Hi all, thanks for the answers to : "regular expression to detect numbers written as words" : http://stackoverflow.com/questions/3608159/regular-expression-to-detect-numbers-written-as-words I now have this working, however I have the same requirement but the numbers as words are in Arabic (or any other UTF-8) and not English, so : i...

preg_match for partial matches

how do i use preg_match for partial matches? when i have the term www.stackoverflow.com and when i enter stackoverflow.com or stackoverflow to match the phrase it returns false. How do i make it work for partial matches? ...

PHP - Parse template variable with regex

Hello, I have to parse this template file ($html) : {$myFirstVariable} {$myMainVar:MYF1,"x\:x\,x",2:MYF2:MYF3,false} {$myLastVariable:trim} Following, my php parser : $regexp = '#{\$(?<name>.+?)(\:(?<modifiers>.+?))?}#'; preg_replace_callback($regexp, 'separateVariable', $html); function separateVariable($matches) { $varname = ...

php preg_match utf-8 strange behaviour

Hi, I search the internet but I couldn't find a proper answer so I try this way. I use this code to validate UTF-8 input. I want to allow printable chars and some specified special chars. $pattern = '/[^\w\.\-\s\,\&\!\?\(\)\+\_\:\;]+$/u'; $status = @preg_match($pattern, $value); if (($status === false) || ($status > 0)) { return f...

extract YouTube URL from random text in PHP

Im trying to extract a YouTube link from just random text. e.g. This is some random text and url is http://www.youtube.com/watch?v=-d3RYW0YoEk&feature=channel and I want to pull this URL out of this text in PHP. Can't seem to figure it out. Found a solution in another language but don't know how to convert it. Thanks for the help....

Regular expression error: no ending delimiter

Hello! I'm trying to execute this regular expression: <?php preg_match("/^([^\x00-\x1F]+?){0,1}/", 'test string'); ?> But keep getting an error: Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in /var/www/preg.php on line 6 I can't understand where it is coming from. I have an ending delimeter right ...

How go get everything from between paranthesis in PHP ?

Array( [1] => put returns (between) paragraphs [2] => (for) linebreak (add) 2 spaces at end [3] => indent code by 4 (spaces!) [4] => to make links ) Want to get text inside brackets (for each value): take only first match remove this match from the value write all matches to new array After function arrays should look like: Array(...