...

View Full Version : Regular Expression Questions, not problem - question.



kaisellgren
11-07-2006, 06:29 PM
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!

marek_mar
11-07-2006, 09:28 PM
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.

kaisellgren
11-08-2006, 05:51 AM
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?

marek_mar
11-08-2006, 06:16 AM
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 ~).

kaisellgren
11-08-2006, 02:09 PM
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\./'



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum