Closed Thread Icon

Topic awaiting preservation: Regular Expressions/PHP (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=12786" title="Pages that link to Topic awaiting preservation: Regular Expressions/PHP (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Regular Expressions/PHP <span class="small">(Page 1 of 1)</span>\

 
u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 06-14-2003 14:59

How can i test a string if it contians one of the characters: \/*?

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 06-14-2003 16:21

preg_match('/[\\\/*?

u-neek
Bipolar (III) Inmate

From: Berlin, Germany
Insane since: Jan 2001

posted posted 06-15-2003 02:54

Thanks.
What further characters are not allowed in a filename?

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 06-15-2003 07:05

Here's something I've always wondered...The search conditions in the preg_replace (like the above example of '/[\\\/*?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-15-2003 12:22

Perl compatible reg exp syntax
- that's the definte read on that topic, skaarjj.
Those 'search conditions' (regular expressions) are a little language of their own.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-15-2003 17:53

In this particular example the arrangement is not important.

What jiblet did was just create his own set of characters by using the square brackets

anything within square brackets creates a set of characters to look for.
[ab] would search for the two characters "a" and "b"

the only bits that make this a little funny to look at is that there's a couple of characters he needed to escape because they are reserved regular expression characters or in the case of the single quote so that he doesn't break the php quote opening the statement.



.:[ Never resist a perfect moment ]:.

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 06-18-2003 17:14

Okay, I did not test that statement to verify that it's exactly correct. The complication is that there are two layers of parsing going on. First PHP parses the string itself. Because I used single quotes, I need to escape the single quote within the string. Additionally, a double backslash will be parsed into one. So while we start with:

preg_match('/[\\\/*?

« BackwardsOnwards »

Show Forum Drop Down Menu