ColdFusion ReReplace reformat phone number

I am trying to reformat a directory of phone numbers from a .pdf file. I extracted all the text and all the phone numbers are in this format. ( 555 ) 555 - 555 I want to put them in it 5555555555, and then <br> I thought to do it #ReReplace(Directory, "\(.*?.\).*?.\-.*?", "", "all")#, but it left spaces and I can not get <br>in. Am I really wrong?

Is it possible to use Rematch to return an array that breaks the string like

["some string ( 555 ) 555 - 555", "some string ( 555 ) 555 - 555", "some string ( 555 ) 555 - 555"] 
+4
source share
2 answers

I kind of hoped that someone would have a better solution, but

, , ( "ENDPN" ) lookahead ReMatch, , , 10 . CF ( , 10) lookbehinds, . Java , .

Lookaheads , ( ), . Lookbehinds , Java, .

10- , .

<cfset Directory = '["some string ( 555 ) 555 - 5768", "some string ( 555 ) 555 - 1234", "some string ( 555 ) 555 - 0101"]'>

<cfset ParseNums = ReReplace(Directory, "\(\s*(\d{3})\s*\)\s*(\d{3})\s*-\s*(\d{4})", "\1\2\3ENDPN", "all")>

<cfset ArrNums = ReMatch("\d{10}(?=ENDPN)",ParseNums)>

<cfdump var="#ArrNums#">

<br /> .

<cfset Directory = '["some string ( 555 ) 555 - 5768", "some string ( 555 ) 555 - 1234", "some string ( 555 ) 555 - 0101"]'>

<cfset ParseNums = ReReplace(Directory, "\(\s*(\d{3})\s*\)\s*(\d{3})\s*-\s*(\d{4})", "\1\2\3<br />ENDPN", "all")>

<cfset ArrNums = ReMatch("\d{10}<br \/>(?=ENDPN)",ParseNums)>

<cfdump var="#ArrNums#">
+1

- ,

#ReReplace(Directory, "\(\s*(\d+)\s*\)\s*(\d+)\s*-\s*(\d+)", "\1\2\3<br>", "all")#
+2

Source: https://habr.com/ru/post/1568214/


All Articles