How to match a string which doesn't contain a dot (.) using regular expression ?
views:
138answers:
3
+8
A:
why regex??
$str="string_with_no_dots";
if ( strpos ($str,"." ) === FALSE ){
print "ok, no dots\n";
}
ghostdog74
2010-02-24 09:26:37
Why? Smells homework assignment long way.
anddoutoi
2010-02-24 09:28:09
because of url rewrite
ivan73
2010-02-24 09:28:24
+3
A:
Create a class matching anything except the specified, which is done using [] with the ^ operator. And, as the comments say, you want to match it against the beginning (^) and the end ($) or the string so that we check the entire string.
^[^.]*$
Mats Fredriksson
2010-02-24 09:29:11
Since . has no special meaning within a class you don't need the \ there.
VolkerK
2010-02-24 09:48:49
@Colin Newell: Yes, because this will otherwise match the first character that isn't a `.` and return true.
R. Bemrose
2010-02-24 15:32:31
A:
Use this regular expression :
if ( !preg_match ( '/\./',$str ,$val ) )
{
print "ok , no dots\n";
}
pavun_cool
2010-02-24 10:45:00