Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question Regular Expression Questions, not problem - question.

    Hi,

    I know regexes quite enough now. I still have some questions i don't know answer myself.

    1. What's the point of delimeter? "/regex/" works just like "regex"
    2. Why do you need to put double quotes? "/my reg code goes here\\./"
    3. Is the regexes in PHP special or are they just like in unixes etc? I see a lot of regexes, do they all work? Is PHP's preg_exes directly copied or a modification?
    4. This "/[\w]/" matches all letters,numbers and underline characters. But how you modify it to match onlie letters and underlines etc? Don't suggets [a-zA-Z...] because I need all letters like Ä,ö Å etc and I dont want to make a big list.

    I really appreciate if you can even answer in one of the questions.

    Thank you!
    PHP 5 & MySQL 5 (Y)

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    1. Because PCRE needs to know when the regexs starts and ends/to separate from modifiers.
    2. Because PHP's language syntax requires strings to be in quotes.
    3. It uses PCRE (read: PHP Manual).
    4. You can exclude by ASCII/UTF code range.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thanks for the help.

    It seems that I had a little mistype in my question.
    2. Why do you need to put double backslashes? "/my reg code goes here\\./"

    Sorry for this stupidness :/

    How do I actually use that code range?
    PHP 5 & MySQL 5 (Y)

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    The backslash is used to escape special characters, both in PHP and in the regex. Your regex will match: "my reg code goes here" then a single backslash and then any character (that is not a newline).
    I'd suggest using single-quotes for regexes as you only have to escape two characters (for PHP), the single quote " ' " and the backslash "\" (most probably only when you don't want it to escape the single-quote).
    To avoid having to escape the delimiter you could change it to a character you don't use in the regex (for example # or ~).
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Um...

    If I type "/my reg code goes here\\./" it will match with "my reg code goes here." ! I just tested it on my server and the double backslashes escapes the single dot.

    These two are exactly the same for me:
    "/my reg code goes here\\./"
    '/my reg code goes here\./'
    PHP 5 & MySQL 5 (Y)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •