[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Remove all characters expect basic alphabet

Posted on 2007-08-02
6
Medium Priority
?
1,793 Views
Last Modified: 2009-06-25
Hi Experts

Is there an easy way to remove all characters except A-Z and a-z from a string?

I have a script that removes all spaces and some punctuation but I don't want to have to write out every single number, punctuation and accent character - I'm mad enough as it is!

Here's the script I'm using:

<%
str = (Recordset1.Fields.Item("CompanyName").Value)

'Remove spaces
Dim regEx, leftStr, rightStr
Set regEx = New RegExp
regEx.Global = true
regEx.IgnoreCase = True

regEx.Pattern = "\s{1,}"

str = Trim(regEx.Replace(str, ""))

'Remove punctuation marks
regEx.Pattern = "(\!|\.|\?|\;|\,|\:,|\&,|\_,|\{,|\},|\[,|\],|\(,|\),|\(,|\),|\~,|\#,|\'|\-)"
str = regEx.Replace(str, "")

'Get the first three and last two letters from the string
leftStr = Left(str,3)
rightStr = Right(str,2)

str = Ucase(leftStr & RightStr)

' Write out the result
Response.Write(str)
%>

Regards

Martin
0
Comment
Question by:Martin Cotterill
  • 3
  • 3
6 Comments
 
LVL 27

Accepted Solution

by:
ddrudik earned 2000 total points
ID: 19618391
reg.Ex.Pattern="[^A-Z]"
0
 
LVL 1

Author Comment

by:Martin Cotterill
ID: 19618437
Hi ddrudik

Thanks for the reply.

So simple yet so brilliant.

Warm regards

Martin
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 19618441
Thanks for the question and the points.  Glad to help.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:Martin Cotterill
ID: 19618451
Just a quickie while I think of it, if I wanted to include numbers, how would it be coded.

Regards

Martin
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 19618456
reg.Ex.Pattern="[^A-Z\d]"
or
reg.Ex.Pattern="[^A-Z0-9]"
0
 
LVL 1

Author Comment

by:Martin Cotterill
ID: 19618468
Thanks d

You're a good 'un

Regards

Martin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question