Say i have a string like "asasd^(&^*&skmw(_^_iolma%(&(%"
From the above string how to extract only alphabets?
The below code helps to retrieve/extract only alphabets from the input string
str="asasd^(&^*&skmw(_^_iolma%(&(%"
Set r=new regexp
r.pattern="[a-z A-Z]"
r.global=true
set s=r.execute(str)
'For each letter in s
'result= letter.value&result
'Next
For i=s.count -1 to 0 step -1
Set oVal=s.item(i)
result=oVal.value&result
next
print result
Now how to retrieve only special characters from the above string?
We can retrieve/extract by either of the below regular expressions.
str="asasd^(&^*&skmw(_^_iolma%(&(%"
Set r=new regexp
r.pattern="[^a-z A-Z]"
'r.pattern="\W"
r.global=true
set s=r.execute(str)
'For each letter in s
'result= letter.value&result
'Next
For i=s.count -1 to 0 step -1
Set oVal=s.item(i)
result=oVal.value&result
next
print result
No comments:
Post a Comment