473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

idiot question about preg_match and regex

I apologize for my igorance of Regex. I can't get this function to
work. It gives the following error message.

function checkForFloatingPoint($input=false) {
$pattern = "[-+]?([0-9]*\.[0-9]+|[0-9]+)";
$match = preg_match (pattern, subject);
echo "The match is: $match ";
return $match;
}


Warning: preg_match(): Delimiter must not be alphanumeric or backslash
in /home/hoovera/public_html/lawrenceScripts/lk_lib.php on line 642
The match is:

Oct 27 '05 #1
6 1724

I know this is bad technique, but if I want to say "any 2 digits
followed by a decimal followed by any 5 more digits" then I could say
this, yes?

[0-9][0-9]\.[0-9][0-9][0-9][0-9][0-9]

Oct 27 '05 #2
On 27/10/2005 14:28, lk******@geocities.com wrote:

[snip]
function checkForFloatingPoint($input=false) {
I don't really see how boolean false is a useful default value, or even
why you'd want a default argument for the input.

What is this function supposed to do? Exactly what pattern(s) are you
trying to match or test for? It's identifier suggests that it should
look for some aspect of a floating-point number (though it's not clear
what), yet your pattern allows integers as well.
$pattern = "[-+]?([0-9]*\.[0-9]+|[0-9]+)";
You haven't included any delimiters. A forward slash, at both the start
and end of the pattern, is common.
$match = preg_match (pattern, subject);


You haven't included the dollar ($) symbol before each identifier.

[snip]

Mike
Don't use tabs to indent. Tabs are usually rendered with the equivalent
of eight spaces, which is far too much when content is usually wrapped
at eighty characters, or less. Use spaces; preferably two.

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 27 '05 #3
just change
$pattern "/[-+]?([0-9]*\.[0-9]+|[0-9]+)/";

see the slashes?

Oct 27 '05 #4
[0-9]{2}\.[0-9]{5}
looks better

Oct 27 '05 #5
>What is this function supposed to do? Exactly what pattern(s) are you
trying to match or test for? It's identifier suggests that it should
look for some aspect of a floating-point number (though it's not clear
what), yet your pattern allows integers as well.


Thank you for help. I apologize for asking such a poor question. I've a
simple one to follow up with: how do you say "not" in regex? Is it "^"?

I've decided that all I want to do is make sure there are no letters in
the input. Is it right to say this:

$pattern "[^A-Za-z]";
$match = preg_match ($pattern, $subject);

This comes back true if there are no letters in $subject, yes?

Oct 28 '05 #6
lk******@geocities.com wrote:
how do you say "not" in regex? Is it "^"?
Yes and no. http://php.net/manual/en/reference.p...ern.syntax.php
I've decided that all I want to do is make sure there are no letters in
the input. Is it right to say this:

$pattern "[^A-Za-z]";


That is not a pattern because it doesn't have pattern delimiters. It also
doesn't have any quantifiers (+, * or {}), or start- or end-of-subject
pinning (^ and $). And you can use a pattern modifier for case-insensitive
matching, see
http://php.net/manual/en/reference.p....modifiers.php

--
E. Dronkert
Oct 28 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sclemens420 | last post by:
On the PHP site on the preg_replace() function page ( http://us3.php.net/manual/en/function.preg-replace.php ), example 1 uses "@" signs in the regular expression members of the "search" array. On...
2
by: Jørn Dahl-Stamnes | last post by:
I try to use preg_match to find out if a string begins with either "http", "/somethime" or "../something". In my php script I have the following line: if (0 ==...
2
by: JanDoggen | last post by:
function vldLicense($lic) { echo "called with lic: ". $lic . "<br>"; echo preg_match('', $lic) . "<br>"; if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false; return true; } gives me:
8
by: Thomas Mlynarczyk | last post by:
Hello, I want to split a given string into tokens which are defined by regexes: // example tokens - a bit more complex in real $tokens = array( 'NUMBER' ='~^\d+~', 'NAME' ='~^+~', 'ANY' ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.