Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find phone number in string
#1
I select numbers on a web page and paste them into a softphone.. alot of times there will be unwanted characters in the selected number like

abc: 800-123-1234 ext123

I use:
str a.getsel
but this gets the whole selection including the abc in front and ext at the end of the phone number

how do i get just the FIRST 10 numbers and disregard everything else including "new line"
I want to get the first 10 characters that match "1234567890" in the string

all i want is the 10 digit phone number to paste into my softphone.. otherwise it wont call.

thanks, nate
#2
Hi,

copy to clipboard your post, then execute this code then use paste in your softphone.

Macro Macro1
Code:
Copy      Help
_s.getclip ;;get clipboard

str s t

;single

findrx(_s "(\d{3}-\d{3}-\d{4})" 0 4 s)
out s
s.trim
s.setclip ;;copies to clipboard

HTH....
#3
more elaborate.

copy all page (its containt) containing numbers to clipboard, then click on the desired number in the list and paste in softphone

Macro Macro2
Code:
Copy      Help
_s.getclip

ARRAY(str) telnumber
str s t ici

foreach s _s
,findrx(s "(\d{3}-\d{3}-\d{4})" 0 4 t)
,if(empty(t)) continue
,t.trim
,telnumber[]=t

_s=telnumber
;
_i=list(_s "" "" 0 0 0 1 1)
s=telnumber[_i-1]
s.setclip

those two examples work only if there is only *one* phone number in a line of original text.
Much complicated if there is more than one phone number per line....

HTH
#4
thanks for the reply

Those two are close but not quite what i need..

i dont want a list. All i want is the first phone number in selected text
I just want the first 10 digit phone number in the text that i select on web page. (no matter whats at the start or end of phone number)
so start with the first character thats a digit (1234567890)
and end with the 10th digit after the first, removing all non digits in between like "().- spaces"

Example 1:
phone: 800-123-1234x12345
new line with other text

Example 2:
myphone: (800)123-1234 x12

Example 3:
your phone number: 800.123.1234

Example 4:
your phone number: 800 123 1234

what i need to end up with:
string s= "8001231234"

thanks for your help with this
#5
Hi Nate,

your needs is far more complicated as you need many phone numbers formatted
in differents ways.

You can just adapt the code to mtch all patterns.

findrx(s "(\d{3}-\d{3}-\d{4})" 0 4 t)

try:

800-123-1234 (\d{3}-\d{3}-\d{4})
(800)123-1234 (\(\d{3}\)\d{3}-\d{4})
800.123.1234 (\d{3}\.\d{3}\.\d{4})
800 123 1234 (\d{3} \d{3} \d{4})


maybe a general one can be found, something like
(\d{3}).*(\d{3}).*(\d{4})

all is non tested, but you get the picture..

HTH
#6
Macro Macro2119
Code:
Copy      Help
out
ARRAY(str) testNumbers; int i
testNumbers[]="phone: 800-123-1234x12345[]new line with other text"
testNumbers[]="myphone: (800)123-1234 x12"
testNumbers[]="your phone number: 800.123.1234"
testNumbers[]="your phone number: 800 123 1234"

str s
for i 0 testNumbers.len
,if(testNumbers[i].replacerx("(?s)\D*(\d)\D*(\d)\D*(\d)\D*(\d)\D*(\d)\D*(\d)\D*(\d)\D*(\d)\D*(\d)\D*(\d).*" "$1$2$3$4$5$6$7$8$9$10" 4)<0) out "invalid"; continue
,out testNumbers[i]


Forum Jump:


Users browsing this thread: 1 Guest(s)