Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 01-14-2008, 02:51 PM preg_match help
Average Talker

Posts: 20
Trades: 0
Hello,

I need a little help with preg_match / regexp, I want only a-z, A-Z (capitals) and 0-9 to be used in $str,

What I've got so far:

Quote:
preg_match("[a-zA-Z0-9]", $str)
This doesn't work, and I'm not exactly a regexp whiz...
koolaid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-14-2008, 09:27 PM Re: preg_match help
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Try
PHP Code:
preg_match("/[a-zA-Z0-9]+/"$str
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE

Last edited by JeremyMiller; 01-14-2008 at 09:28 PM..
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 01-14-2008, 11:15 PM Re: preg_match help
phpknowhow's Avatar
Skilled Talker

Posts: 83
Name: Colin
Location: USA
Trades: 0
I would actually use:
PHP Code:
preg_match("/^[a-zA-Z0-9]+$/"$str
It seemed as though you wanted to only match those charactors in the set. If you don't add the ^ (beginning of string) and $ (end of string), then the pattern could match only a section of the string, and not the whole thing.

Pattern Syntax:
http://us3.php.net/manual/en/referen...ern.syntax.php
__________________

Please login or register to view this content. Registration is FREE
| Freelance PHP solutions for small to midsized projects |
Please login or register to view this content. Registration is FREE
phpknowhow is offline
Reply With Quote
View Public Profile Visit phpknowhow's homepage!
 
Old 01-15-2008, 02:05 AM Re: preg_match help
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Good clarification, phpknowhow. I hardly ever use the ^ and $ symbols in regexs b/c I'm not that great at them in the first place. I really appreciate your explanation as to why using them benefits the expression.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 01-15-2008, 08:43 AM Re: preg_match help
Average Talker

Posts: 20
Trades: 0
Quote:
Originally Posted by phpknowhow View Post
I would actually use:
PHP Code:
preg_match("/^[a-zA-Z0-9]+$/"$str
It seemed as though you wanted to only match those charactors in the set. If you don't add the ^ (beginning of string) and $ (end of string), then the pattern could match only a section of the string, and not the whole thing.

Pattern Syntax:
http://us3.php.net/manual/en/referen...ern.syntax.php
Thanks that one worked.

Last edited by koolaid; 01-15-2008 at 08:47 AM..
koolaid is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to preg_match help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21765 seconds with 12 queries