• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1799
  • Last Modified:

Remove all characters expect basic alphabet

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
Martin Cotterill
Asked:
Martin Cotterill
  • 3
  • 3
1 Solution
 
ddrudikCommented:
reg.Ex.Pattern="[^A-Z]"
0
 
Martin CotterillDabblerAuthor Commented:
Hi ddrudik

Thanks for the reply.

So simple yet so brilliant.

Warm regards

Martin
0
 
ddrudikCommented:
Thanks for the question and the points.  Glad to help.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Martin CotterillDabblerAuthor Commented:
Just a quickie while I think of it, if I wanted to include numbers, how would it be coded.

Regards

Martin
0
 
ddrudikCommented:
reg.Ex.Pattern="[^A-Z\d]"
or
reg.Ex.Pattern="[^A-Z0-9]"
0
 
Martin CotterillDabblerAuthor Commented:
Thanks d

You're a good 'un

Regards

Martin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now