Jump to content


what is this expression do?

  • Please log in to reply
3 replies to this topic

#1 bilis_money

  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 18 June 2006 - 02:19 AM

hi, i'm really very new to REGEX

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

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

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

thank you very much.

#2 poirot

  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 18 June 2006 - 04:41 AM

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.
~ D Kuang

#3 bilis_money

  • Members
  • PipPipPip
  • Advanced Member
  • 621 posts

Posted 18 June 2006 - 05:42 AM

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.

#4 Ninjakreborn

  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 19 June 2006 - 04:17 PM

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


Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users