More questions on Regular Expressions

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Toasty
-


Joined: 21 Feb 2008
Posts: 298
Location: Chicago, IL

PostPosted: Sat Apr 25, 2009 11:05 am    Post subject: More questions on Regular Expressions Reply with quote

Okay, so I know I've gotten quite a bit of help in the past from you guys on RegEx. I am really no good at it, so I'd like to see if maybe you guys can give me a hand at this.

Below is my current code that strips out everything except letters and numbers:

Code:
$var = ereg_replace("[^A-Za-z0-9]", "",$var)


I was wondering if somebody can tell me how to allow each of these:

Underscore

Dash

Period

Question Mark

Exclamation Mark

Quote/ Double Quote



It would be great if you could tell me each one individually, it would help me figure out what I need to add for each character. There are some times I don't want to use some of these characters.


Thanks in advance for any help!
-Toasty
_________________
Audit the secure configuration of your server headers!
Back to top View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Sat Apr 25, 2009 11:05 pm    Post subject: Re: More questions on Regular Expressions Reply with quote

Toasty wrote:
Okay, so I know I've gotten quite a bit of help in the past from you guys on RegEx. I am really no good at it, so I'd like to see if maybe you guys can give me a hand at this.

Below is my current code that strips out everything except letters and numbers:

Code:
$var = ereg_replace("[^A-Za-z0-9]", "",$var)


I was wondering if somebody can tell me how to allow each of these:

Underscore

Dash

Period

Question Mark

Exclamation Mark

Quote/ Double Quote



It would be great if you could tell me each one individually, it would help me figure out what I need to add for each character. There are some times I don't want to use some of these characters.


Thanks in advance for any help!
-Toasty


Should work by throwing the characters in the character class (i.e. within the brackets).
Code:
$var = ereg_replace("[A-Za-z0-9_\-\.?\!\'\"]", "",$var)


Some of the characters need to be escaped - some may not be. It probably hurts less to over-escape. At quick glance, a replace function shouldn't need the carat in the regex. That's only useful for matching regex functions.

Good website: http://regular-expressions.info
Recommended program: The Regex Coach
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group