Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions search in a string 1

Status
Not open for further replies.

Suppy

Technical User
Jul 22, 2002
12
RO
Hello.
I have a problem.
I want to check if a string contains letters(it may contains numbers or other caracters).I want to remove the letters from the string.
I don't know how to do it.
I don't want to use "instr()" because i have to right many times the same thing and it is not very useful.
Maybe someone knows how to use regular expressions and can give me a hint or a solution.
Thanks a lot.
 
try looping through the string and building another, something like this:
'**************************
dim strOriginal, strNew, I

for I = 1 to len(strOriginal)
if IsNumeric(mid(strOriginal,I,1)) = false then
strNew = strNew & mid(strOriginal,I,1)
end if
next I
'***************************

That should build you an alpha string. 'mi casa es su casa'
]-=tty0=-[
ICQ:82621399
 
Hi Suppy,
There is a regular (built-in) function for this:

:: Replace(expression, find, replacewith[, start[, count[, compare]]])

For example:
<%
dim vsContent, vsToRemove, vsNewString

vsContent = &quot;The Quick Brown Fox Jumped Over The Lazy Cat.&quot;
vsToRemove = &quot;Quick Brown &quot;

vsNewString = REPLACE( vsContent, vsToRemove, &quot;&quot; )
Response.Write( vsNewString & &quot;<BR>&quot; & vbCRLF )
%>
will get &quot;The Fox Jumped Over The Lazy Cat.&quot;


regards,
- Joseph ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Shopping --> , Soccer --> ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
Here is an example of removing all the letters from a string:
Code:
<%
Dim strContent, strNewContent
Set RegExpObj = New RegExp

With RegExpObj
.Pattern = &quot;[A-Z]&quot;   'will cover a-zA-Z since ignore case is on
.IgnoreCase = True
.Global = True
End With

strNewContent = RegExpObj.Replace(strContent, &quot;&quot;)

Response.Write &quot;Original: &quot; & strContent & &quot;<br>&quot;
Response.Write &quot;New: &quot; & strNewContent

Set RegularExpressionObject = nothing
%>

That should handle it for you,
Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top