Re: QF - regex rule
| From: | Justin Patrin | Date: | Wed, 12 May 2004 05:20:19 +0000 |
| Subject: | Re: QF - regex rule | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12427@lists.php.net to get a copy of this message | ||
Daniel Kopp wrote:
Hi! I am trying to use the regex rule to exclude forbidden characters of filenames in a textbox. The forbidden characters (Windows) are: "\/:*?"<>" so I tried something like: [^\/:*?"<>] first and then {[^\/:*?"<>]}, {.*[^\/:*?"<>].*} and a lot stuff like that but the result is always that the rule only works for a single forbidden character. So when I write: "blabla*" it gets through while "*" does not go through. Is there a docu for regex-rule somewhere? The current docu does not even say whether the regex should match or not ... I am starting to hate phps regex more and more ... Perl was much more clear to me ... Maybe I am wrong but to me "Perl style" seems to be not really true ... Can someone help me? Thanks Daniel....AFAIK, the PREGs in PHP are near the same as perl. I've never really noticed a difference between perl and PHP PREGs. Are you sure you're using the preg functions and not ereg functions? First, If you want to match all those chars you'll need this character class: [^\\/:*?"<>] You have to escape the backslash. Second, the first regex you gave should catch those chars anywhere. Perhaps you need to add delimiters? ![^\\/:*?"<>]! You could also try escaping * and ? inside that char class, although I don't think they need to be. If that doesn't work, maybe try: !^.*?[^\\/:*?"<>].*?$! BTW, the manual can give you anything you need: http://php.net/preg You can also use the Regex coach to test your regexes. http://www.weitz.de/regex-coach/ -- paperCrane <Justin Patrin>