preg-match

Need to reverse this regex pattern, but no clue how...

I found a regex pattern for PHP that does the exact OPPOSITE of what I'm needing, and I'm wondering how I can reverse it? Let's say I have the following text: Item_154 ($12) This pattern /\((.*?)\)/ gets what's inside the parenthesis, but I need to get "Item_154" and cut out what's in parenthesis and the space before the parenthesis. ...

Enable whitespace in php regular expresssion

I want to have A-Z, 0-9 and whitespace ignored in regular expression, currently I have this, it works but whitespaces are ignored too but I need them. preg_match_all("/[^\w]/",$string,$matches); ...

PHP REGEX: Ignore + and #

So here is what I'm doing exactly: I have a form with a caption on the right of it, I want to write in the form only A-Z,0-9 and whitespaces, and for the caption I want to do the opposite, so if the user write's something wrong I can show what's the problem for example: "Invalid Charachter" But I'm stuck with + and # I want to ignore ...

What does this regular expression mean?

What does this regular expression mean? preg_match("/^obj(\d+)\-{0,1}(|mi\d{0,1}|critical|questionText|answerText\-{0,1}\d+)$/", $k, $a) the preg_match is a php function that should translate it ...

Having an issue with preg_match() in PHP

Hello SO: I am a bit rusty at PHP, so bear with me. I am making a simple email form that validates a few key pieces of data. One of these fields is the submitter's zip code. To validate this, I figured a regex would be simple since I am pretty confident the validation can be done in one line. Behold: preg_match("^([0-9]{5}|[0-9]{5}\-[0...

pregmatch separate number and character

Hi this is my keyword BC1024 , AB124 , CBC2548 , using preg match to separate the number and character , For that i tried this preg match expression , but its not working greatly , preg_match_all('/(?P\w+): (?P\d+)/', $flight_code_no, $matches,PREG_PATTERN_ORDER); i want output as Array ( [0] => BC1024: 2008 [name] =>...

Regular Expression PHP Help with if not equal to

I am trying to use regular expressions to make my inventory upload script a little better. I sell clothing and accessories. In my inventory file I have a field called ProductDepartment which is a combination of gender/item type. I have a MySQL table for gender with the following values: Mens = 1 Womens = 2 Unisex = 3 Departments in...

preg match not reading content between table

preg_match_all('|(.*?)|', $read, $foo, PREG_SET_ORDER); print_r($foo); output as just Array ( ) Where i made mistake See guys , Actually i want to grab the exact details from this URL i want to pick this details from this URL 08:35 9W5048 TORONTO EXPECTED 1358 Terminal three So i tried this snippet , but...

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

How can I find a single occurrence of a non-latin character using regular expressions?

I am using a regular expression to see if there is a single non-latin character within a string. $latin_check = '/[\x{0030}-\x{007f}]/u'; //This is looking for only latin characters if(preg_match($latin_check, $_POST['full_name'])) { $error = true; } This should be checking to see if there is at least one character pres...

Is my preg_match syntax valid?

I'm adding an if statement to my database abstraction layer to pick out any attempted queries to a handful of database tables. Basically, if my application attempts to create, read or destroy data from a database table called either members or members_profiles I want to invoke my if statement. if ( preg_match('/INSERT INTO [members...

extracting secret password from string using preg_match?

how can I use preg_match to extract secret_password from this string? s:6:"secret_password" ...

PHP: how to create an regexp to preg_match() for PT Mobile phones?

Hi all, i'm newer related to Regexp on PHP... I need to create an Regexp to filter Portuguese Mobile Phones, can anybody help me and explain how i do it? (To i understand it) Rules: The integer/string must have 9chars; The first char must be a '9'; The second one can be '1,2,3,6' (Chars are separeted by commas); The other chars must b...

How can I get the current web directory from the URL?

If I have a URL that is http://www.example.com/sites/dir/index.html, I would want to extract the word "sites". I know I have to use regular expressions but for some reason my knowledge of them is not working on PHP. I am trying to use : $URL = $_SERVER["REQUEST_URI"]; preg_match("%^/(.*)/%", $URL, $matches); But I must be doing som...

RegEx not working with look-aheads!

Hey guys, I am trying to match "address" in this page - http://www.bbb.org/norfolk/business-reviews/tax-return-preparation/liberty-tax-service-in-virginia-beach-va-48000604 The source of address part has this HTML <tr> <td align="right" class="generalinfo_left">Address:</td> <td class="generalinfo_right">1 S Main St Ste 1430<b...

how to force preg_match preg_match_all to return only named parts of regex expression

example: <?php $string = "This is some text written on 2010-07-18."; preg_match('|(?<date>\d\d\d\d-\d\d-\d\d)|i',$string,$arr_result); print_r($arr_result); ?> returns: Array ( [0] => 2010-07-18 [date] => 2010-07-18 [1] => 2010-07-18 ) but I want it to be: Array ( [date] => 2010-07-18 ) in php's pdo object there ...

Regular Expression to Validate Long URLs in PHP

I am looking for help in creating a Regular Expression that validates a URL of very long length (eg. a very long Google Maps address). I am new to regular expressions and I am using it in PHP with preg_match(). I have used the expression: preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/...

How to preg_match parent div?

Hi guyz, I need to get all contents of div class = "parent" using preg_match, <div class = "parent"> <div id = "child1"> </div> <div id = "child2"> </div> </div> Anyone? ...

preg_match help, simple for most

I'm trying to match all the URLs that end in .html and if they have ? after it's OK but if it's odd then not so preg_match("/article-(.+?).html/i", getenv('REQUEST_URI')) <-- good preg_match("/article-(.+?).html*?*/i", getenv('REQUEST_URI')) <-- good basically i want to match it if it end in .html or ends in .html? and if it has a ? ...

PHP - extracting specific <a href> urls out of the document

I think this should be elementary, but I still cant't get my head around it. Let's say there's fair amount of HTML documents and I need to catch every image urls out of them. The rest of the content changes, but the base of the url is always the same for example http://images.examplesite.com/images/, so I wan't to extract every string t...