PHP - Negative Lookahead
Hi Guys
Bit stuck on a negative lookahead and not sure that what i want to achieve is possible.
Lets says I have a domain: www.mysite.com
I want to have a regex that will match www.mysite.com?q=123&g=34 but I don't want to match any file extensions like .php or .html
So the first part of matching the query string and the literal url is fairly straightforward (below) which matches any query string that may be applied
/^www.mysite.com[\/]?[\?\=\&a-z0-9]*$/But then I want to use a negative lookahead to avoid matching a file extension, e.g. /^www.mysite.com[\/]?[\?\=\&a-z0-9](?!php|html|htm)$/But this doesn't work - presumably because the negative lookahead is following a character class. So my questions: can you use a negative lookahead in this way? If not, how can I achieve what I'm trying to? Any help appreciated! Drongo Similar TutorialsI need to match n occurrences of "." in a string following specific rules.
The number of occurrences found by the regex should correspond with the exact amount of "."'s in the string.
The rules a
1) every "." must be preceded by at least one digit from 1-9, and can be preceded by up to two other digits from 0-9 (basically, values from 1-999)
2) every "." must be followed by at least one digit from 1-9, and can be followed by up to two other digits from 0-9 (again, values from 1-999).
Sample valid strings a
1) "1.3.5.7.9"
2) "21.23.25.27.29"
Sample invalid strings a
1)"01.5.7.9" (first digit of the number preceding the dot cannot be a zero)
2) "1.05.7.9" (first digit of the number preceding or following the dot cannot be a zero)
3) "1.5.7777.9999" (cannot have more than 1 digit with value 1-9 and up to two more digits with value 0-9 (so up to 3 digit numbers); here we have four digit numbers)
I'm using preg_match_all to match all occurrences of the dot in the string, and I'm using lookaheads seeing that the digits matched are shared between the dots (the same digit that is preceding a dot is following another dot). The problem is, when I have two or three digit numbers, I'm getting more matches than I need.
Here is my pattern: /(?=([1-9][0-9]{0,2}\.[1-9][0-9]{0,2}))/
Here is my test subject: "Mt1,1-15.17.19"
There are only two dots, but I am getting four matches:
array ( How do I reverse the logic of my Regex statement so it says, "If there is NOT a match..." Code: [Select] // (Replacement for non-supported Email-Filter.) if (preg_match('#^[A-Z0-9_\+-]+(\.[A-Z0-9_\+-]+)*@[A-Z0-9-]+(\.[A-Z0-9-]+)*\.([A-Z]{2,7})$#i', $trimmed['senderEmail'])){ // Valid Email. // ??? }else{ // Invalid entry. $errors['senderEmail'] = 'Please enter a valid E-mail address.'; }// End of VALIDATE ENTRY. I want to do this so I don't have an empty THEN statement! Debbie <?php if ($beyondportal % 26 == 0 || $beyondportal == 0){ ?> MY CONTENT <?php } ; ?> This code compares my variable $beyondportal and if it is a multiple of 26 counting up from 0, it prints my content. This is great but sometimes the number comes up a negative that is a multiple counting down from 0 like -26, -52, etc.. if I could do the opposite of a modulus I would think it would work but I'm not sure how to in php. any suggestions? Hi all I am adding some positive and negative numbers. But i am getting strange output. Can anyone help me Here is the code. Code: [Select] $sum=7.50+6.45+12.90+12.00+13.00+0.61+32.00+4.00+27.00+18.00+10.88+129.50+92.94-100.00-38.25+76.80-305.33; echo "<br>Total: ".$sum; Basically i have to get Total is 0 but i am getting total is 5.6843418860808E-14 Can anyone help me out Please I have a code to sum up a field called quantityHand in MySQL, in my example below, the value always return 40 as a positive number instead of 40.00- 0.00 0.00 40.00- I have used intval() or floatval() function to convert the type of variable from string to int/float but still not working. Any help please? Here is the code Code: [Select] $sql = mysql_query("SELECT DISTINCT itemNumber, itemDesc, quantityHand, SUM(quantityHand) AS quantityHand FROM inventory where itemNumber like '%$term%' GROUP BY `itemNumber` ORDER BY `itemNumber`"); while ($row = mysql_fetch_array($sql)){ echo "<b>"; echo "</td><td style=\"text-align: center;\"><b>"; echo $row['itemNumber']; echo "</td><td style=\"text-align: center;\"><b>"; echo $row['itemDesc']; //echo "</td><td style=\"text-align: right;\">"; echo "</td><td style=\"text-align: center;\"><b>"; echo $row ['quantityHand']; echo "</td></tr>"; echo "</b>"; This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=353188.0 I'm curious, is there any reason to use array_pop($value) at all when you can explode(' ', $value, -1) ??? Besides being php version < version 5.1.0 compatible of course. Hi, How can I check if a variable only has these characters: - number (0-9) - decimal point (.) - positive (+) - negative (-) - dollar ($) I tried is_numeric, but it doesn't like negative values... I need to add the variable value to another variable. I have to accept numbers (including negative and decimals)... ex: 0.1 = TRUE -.1 = TRUE 12 = TRUE 1000.00 = TRUE 12a = FALSE thanks Aside from money_format(), is there another way to use "()" instead of "-" for negative numbers? Actually, using money_format() would be best for me but I've read somewhere that list of locale differ from server to server. Unfortunately, I cannot identify the list of locale supported on the server I'm using (Heliohost) since system('locale -a') is disabled. Thanks in advance! This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=322815.0 hello, i have a start time and an end time (no dates). the following works great, except for when the start time is at night, and the end time is in the morning. im thinking if i can do an if the number is negative, add 24, that it will resolve my issue. any ideas? Code: [Select] $tbilled = $tfinish - $tstart; |