Jump to content

Archived

This topic is now archived and is closed to further replies.

bilis_money

what is this expression do?

Recommended Posts

hi, i'm really very new to REGEX

but i think i have a basic question.
and the code was;

[code]preg_match ("/userfile_[1-5]{1}/", $name)[/code]

what is this code do?
please explain it in detail?

thank you very much.


Share this post


Link to post
Share on other sites
Splitting it:

"/" is the starting delimiter
"userfile_" matchs the string "userfile_" (literal)
"[1-5]" is a character class, numbers from 1 to 5
"{1}" is a quantifier (1 time)
"/" is the ending delimiter

It will match userfile_1, userfile_2, userfile_3, userfile_4, and userfile_5.

But since there are no anchors (^ and $) this means it will also match strings with anything before and after it.

Share this post


Link to post
Share on other sites
hi poirot,
how long you had learned REGEX?
and what book do you have?
is it Jeffrey Freidl's book?

i guess i need more REGEX story and samples so that i can absorb them well
and to be familiarize as well.

thanks for your answers.

Share this post


Link to post
Share on other sites
Buy a copy of Programming PHP first version(don't know about the second), from a company called oreilly, by the time you read through there 2-3 pages on regex, you will understand fully all of the basics of regex, until you get down to themore involved stuff, you won't be able to make your own at that point, but atleast you will know what you are reading, and have quick references, you can look up anything under there regex, perl compatible, and post ex

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.