Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 4th, 2009, 11:03 AM
mattmauldin mattmauldin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 1 mattmauldin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 59 sec
Reputation Power: 0
Remove Alphanumerics Except for +

I need some help, guys. This is the first time I've had to work with regex, and it's kicking my butt right now.

This function is currently taking out all the non-alphanumeric characters from a URL in a URL rewrite and caching script I am using. But I want to change the regex so that the + symbol remains.

Here's the original function:
Code:
function removeNonAlphaNumeric($name, $name_delimiter){
                       return preg_replace("/[^a-zA-Z0-9]/", $name_delimiter, $name);
               }



I've already tried this without success:
Code:
function removeNonAlphaNumeric($name, $name_delimiter){
                       return preg_replace("/[^a-zA-Z0-9\+]/", $name_delimiter, $name);
               }


Any ideas?

Reply With Quote
  #2  
Old November 4th, 2009, 03:43 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 16,673 Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 17th Grade (Above 100000 Reputation Level) 
Time spent in forums: 4 Months 3 Days 20 h 26 m 53 sec
Reputation Power: 2121
Welcome to DevShed Forums, mattmauldin.

Try this:
Code:
function removeNonAlphaNumeric($name, $name_delimiter){
                       return preg_replace("/[^a-zA-Z0-9\+\040]/", $name_delimiter, $name);
               }

The "\040" means a space character.
__________________
Spreading knowledge, one newbie at a time.

Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

Check out my blog.

Reply With Quote
  #3  
Old November 4th, 2009, 03:49 PM
requinix's Avatar
requinix requinix is offline
nuts - top 5 poster again :(
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 5,402 requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)requinix User rank is General 32nd Grade (Above 100000 Reputation Level)  Folding Points: 163825 Folding Title: Super Ultimate Folder - Level 1Folding Points: 163825 Folding Title: Super Ultimate Folder - Level 1Folding Points: 163825 Folding Title: Super Ultimate Folder - Level 1Folding Points: 163825 Folding Title: Super Ultimate Folder - Level 1Folding Points: 163825 Folding Title: Super Ultimate Folder - Level 1Folding Points: 163825 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 1 Day 4 h 12 m 59 sec
Reputation Power: 3078
Send a message via MSN to requinix
I'd recommend adding a + (as in repetition):
Code:
/[^...]+/

Without, "Programming Languages - More" could turn into "Programming-Languages---More".
With, you get "Programing-Languages-More".

I'd also recommend trimming off the $name_delimiter from the start and end.
Code:
"Programming Languages (More)"     before
-> "Programming-Languages-More-"   after regex
-> "Programming-Languages-More"    after trim
__________________
How to ask a PHP question | My stuff

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Remove Alphanumerics Except for +


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek