fmendi Posted December 28, 2020 Share Posted December 28, 2020 Hi, I hadn't posted in such long time that my profile was deleted so I re-subscribed as fmendi... Anyway, I'm sure there are members here that use the PayPal shipping service to print out labels which requires copying and pasting each element of the recipient's address into the different fields . https://www.paypal.com/shiplabel/create For example, copy the following into clipboard and using the following script works well except for a few things... Frank Conte 2133 Elm St. Gainesville FL, 45679. $_full_add = ClipGet() ; places copied full address into ClipGet $_last_line = StringRegExp($_full_add, "(?si)^.*\n(.*)$", 1) ;Last line of address $_name = StringRegExp($_full_add, "\A.*", 1) ;First line - full name $_add = StringRegExp($_full_add, "(?:\r\n?|\n)(.+)", 1) $_city = StringRegExp($_last_line[0], "^[^\s]+", 1) ;First word of last line $_state = StringRegExp($_last_line[0], "\s+[^\s]+", 1); Second last word in line $_zip = StringRegExp($_full_add, ".*([0-9]{5})", 1) ;Last full "word" MsgBox(1, "", $_zip[0]) MsgBox(1, "", $_state[0]) MsgBox(1, "", $_city[0]) MsgBox(1, "", $_add[0]) 1. If there is more than one word in the city's name (eg New York), only the first word is captured and the zip code becomes the second word 2. If State is followed by a comma, $_zip will also include the comma 3. If the address is given in one line only, the script falls apart eg Frank Conte 2133 Elm St. Gainesville FL, 45679. 4. God knows what other variations of the address may fail My experience with StringRegExp is limited to say the least, any help would be appreciated. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 28, 2020 Moderators Share Posted December 28, 2020 fmendi, We do not delete accounts unless asked - there is an "fmen" account still up and running which I presume is yours. But feel free to stick with this new one. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Nine Posted December 28, 2020 Share Posted December 28, 2020 (edited) Here a first draft. If you find new format of address, include them in the array, we will see how we can solve it. #include <Constants.au3> #include <Array.au3> Local $aAddr = [ _ "Frank Conte 2133 Elm St. Gainesville FL, 45679.", _ "Frank F. Conte" & @CRLF & "123 First Rd." & @CRLF & "New York NY, 12345." ] Local $aComp For $sAddr in $aAddr $aComp = StringRegExp($sAddr, "(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)", 1) _ArrayDisplay($aComp) Next Edited December 28, 2020 by Nine Extract state also... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
fmendi Posted December 28, 2020 Author Share Posted December 28, 2020 Awesome work, Nine. I don't think I'd have ever come up with such the elegant regex such as: (?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+) Two further questions will really expose my ignorance to both regex and arrays... 1. The results place City and State into one element. I need those separated into individual elements but have no idea on how. 2. How can I extract the 5 different elements from the array into variables to be able to paste them into the PayPal form? I'm looking at _ArrayToClip() and_ArrayToString() with little success. Thank you for the help.... Link to comment Share on other sites More sharing options...
Nine Posted December 28, 2020 Share Posted December 28, 2020 (edited) 23 minutes ago, fmendi said: 1. The results place City and State into one element. I need those separated into individual elements but have no idea on how. Not in my case : 23 minutes ago, fmendi said: 2. How can I extract the 5 different elements from the array into variables to be able to paste them into the PayPal form? There is no need to transfer (extract) the content of the array to variables. You can use them individually by using the index (0-based). For example to get the name use $aComp[0], for city use $aComp[2], for zip $aComp[4], etc... ps Make sure you got the latest code I posted, I made a small modif to extract state separately Edited December 28, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Developers Jos Posted December 28, 2020 Developers Share Posted December 28, 2020 5 hours ago, fmendi said: Hi, I hadn't posted in such long time that my profile was deleted so I re-subscribed as fmendi... Doubt that as we don't delete accounts unless requested. So what was your original account? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
fmendi Posted December 28, 2020 Author Share Posted December 28, 2020 I cannot thank you enough, Nine. Hopefully this will be useful for other members. Here's the full script... Before running the script copy the full address into the clipboard and have the cursor focused on "Customer Name" in the Paypal shipping form. Any improvements are welcome, of course. expandcollapse popup;Autofill PayPal Shipping Page #include <Constants.au3> #include <Array.au3> Local $aComp = clipGet() Local $aAddr = [$aComp] For $sAddr in $aAddr $aComp = StringRegExp($sAddr, "(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)", 1) Next If $aComp[3] = "AL" Then $aComp[3] ='Alabama' If $aComp[3] = "AK" Then $aComp[3] ='Alaska' If $aComp[3] = "AZ" Then $aComp[3] ='Arizona' If $aComp[3] = "AR" Then $aComp[3] ='Arkansas' If $aComp[3] = "CA" Then $aComp[3] ='California' If $aComp[3] = "CO" Then $aComp[3] ='Colorado' If $aComp[3] = "CT" Then $aComp[3] ='Connecticut' If $aComp[3] = "DE" Then $aComp[3] ='Delaware' If $aComp[3] = "DC" Then $aComp[3] ='District of Columbia' If $aComp[3] = "FL" Then $aComp[3] ='Florida' If $aComp[3] = "GA" Then $aComp[3] ='Georgia' If $aComp[3] = "HI" Then $aComp[3] ='Hawaii' If $aComp[3] = "ID" Then $aComp[3] ='Idaho' If $aComp[3] = "IL" Then $aComp[3] ='Illinois' If $aComp[3] = "IN" Then $aComp[3] ='Indiana' If $aComp[3] = "IA" Then $aComp[3] ='Iowa' If $aComp[3] = "KS" Then $aComp[3] ='Kansas' If $aComp[3] = "KY" Then $aComp[3] ='Kentucky' If $aComp[3] = "LA" Then $aComp[3] ='Louisiana' If $aComp[3] = "ME" Then $aComp[3] ='Maine' If $aComp[3] = "MD" Then $aComp[3] ='Maryland' If $aComp[3] = "MA" Then $aComp[3] ='Massachusetts' If $aComp[3] = "MI" Then $aComp[3] ='Michigan' If $aComp[3] = "MN" Then $aComp[3] ='Minnesota' If $aComp[3] = "MS" Then $aComp[3] ='Mississippi' If $aComp[3] = "MO" Then $aComp[3] ='Missouri' If $aComp[3] = "MT" Then $aComp[3] ='Montana' If $aComp[3] = "NE" Then $aComp[3] ='Nebraska' If $aComp[3] = "NV" Then $aComp[3] ='Nevada' If $aComp[3] = "NH" Then $aComp[3] ='New Hampshire' If $aComp[3] = "NJ" Then $aComp[3] ='New Jersey' If $aComp[3] = "NM" Then $aComp[3] ='New Mexico' If $aComp[3] = "NY" Then $aComp[3] ='New York' If $aComp[3] = "NC" Then $aComp[3] ='North Carolina' If $aComp[3] = "ND" Then $aComp[3] ='North Dakota' If $aComp[3] = "OH" Then $aComp[3] ='Ohio' If $aComp[3] = "OK" Then $aComp[3] ='Oklahoma' If $aComp[3] = "OR" Then $aComp[3] ='Oregon' If $aComp[3] = "PA" Then $aComp[3] ='Pennsylvania' If $aComp[3] = "RI" Then $aComp[3] ='Rhode Island' If $aComp[3] = "SD" Then $aComp[3] ='South Dakota' If $aComp[3] = "TN" Then $aComp[3] ='Tennessee' If $aComp[3] = "TX" Then $aComp[3] ='Texas' If $aComp[3] = "UT" Then $aComp[3] ='Utah' If $aComp[3] = "VA" Then $aComp[3] ='Virginia' If $aComp[3] = "WA" Then $aComp[3] ='Washington' If $aComp[3] = "WV" Then $aComp[3] ='West Virginia' If $aComp[3] = "WI" Then $aComp[3] ='Wisconsin' WinActivate("PayPal") Sleep(1000) Send($aComp[0] & "{tab}" & $aComp[1] & "{tab 2}" & $aComp[2] & "{tab}" & $aComp[3] & "{tab}" & $aComp[4] ) Link to comment Share on other sites More sharing options...
fmendi Posted January 3, 2021 Author Share Posted January 3, 2021 On 12/28/2020 at 11:36 AM, Nine said: Here a first draft. If you find new format of address, include them in the array, we will see how we can solve it. #include <Constants.au3> #include <Array.au3> Local $aAddr = [ _ "Frank Conte 2133 Elm St. Gainesville FL, 45679.", _ "Frank F. Conte" & @CRLF & "123 First Rd." & @CRLF & "New York NY, 12345." ] Local $aComp For $sAddr in $aAddr $aComp = StringRegExp($sAddr, "(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)", 1) _ArrayDisplay($aComp) Next @Nine So far, I've found two variations that break the regex: 1. If the State is in small letters (eg fl instead of FL) 2. If there is a comma after the City (eg Orlando, FL) Thanks... Link to comment Share on other sites More sharing options...
seadoggie01 Posted January 4, 2021 Share Posted January 4, 2021 (edited) 1. From everything I can see, it looks like the RegEx isn't dependent on capital letters. Using the global flag (?i) makes RegEx not be case-sensitive. You can add this to the (?s) flag at the beginning like (?si). Alternately, capture lowercase letters as well as uppercase -- from [A-Z] to [a-zA-Z] 2. You mean sometimes there isn't a comma? You can make something in RegEx optional by using a question mark. 3. Do you ever have zip code extensions? (a 4 digit code after the zip code) You won't capture them currently. 1: (?si)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+) Or... (?s)([^\d]+)([^.]+\.)\h*(.*?)([a-zA-Z]{2}),\h*(\d+) 2: (?si)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),?\h*(\d+) 3: (?si)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),?\h*(\d+(?:-\d+)?) Edited January 4, 2021 by seadoggie01 Zip... code :) FrancescoDiMuro 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
fmendi Posted January 6, 2021 Author Share Posted January 6, 2021 Thank you so much @seadoggie01 ! The two issues are now corrected. Hopefully there won't be others. I wish my brain was wired like yours to fully comprehend this incredibly helpful regex tool. Link to comment Share on other sites More sharing options...
seadoggie01 Posted January 6, 2021 Share Posted January 6, 2021 20 minutes ago, fmendi said: I wish my brain was wired like yours No, trust me, you don't 20 minutes ago, fmendi said: incredibly helpful regex tool I think I learned just about everything I know from RegEx101.com. It's also amazingly helpful to test RegEx instead of trying it in a script repeatedly. FrancescoDiMuro 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 6, 2021 Share Posted January 6, 2021 (edited) @fmendi If you want to "split" the pattern to understand what each piace of it means, then you can paste the pattern here and read the description of the various pieces in the top-right side of the window EDIT: Nice one @seadoggie01! Edited January 6, 2021 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
fmendi Posted January 25, 2021 Author Share Posted January 25, 2021 RegEx101.com is a great resource.! Thank you both for the suggestion. I have been trying different test strings to figure out how to make StringRegExp($sAddr, "(?s)([^\d]+)([^.]+\.)\h*(.*?)([A-Z]{2}),\h*(\d+)", 1) work without a period at the end of the street address (123 Elm St.), but my brain started hurting. I took out the \. from the second capturing group ([^.]+\.) and it sort of worked, but the period now appears in the third capturing group before the city ie. . New York. I would like for the regex to work both with and without a period at the end of the street address. Sorry for continuing to ask for help, but know it is deeply appreciated. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 25, 2021 Share Posted January 25, 2021 @fmendi Could you please post a bunch of test strings and the expected results? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
fmendi Posted January 25, 2021 Author Share Posted January 25, 2021 18 minutes ago, FrancescoDiMuro said: @fmendi Could you please post a bunch of test strings and the expected results? Sure, Thanks... 1. John Ham 123 elm st. New York NY, 12323 -expected ---> 1. John Ham 2. 123 elm st. 3. New York 4. NY 5. 12323 ---> Works 2. John Ham 123 elm st New York NY, 12323 -expected ---> 1. John Ham 2. 123 elm st 3. New York 4. NY 5. 12323 ---> Does not work because of the missing period (.) after 123 elm st Eliminating \. from regex 3. John Ham 123 elm st. New York NY, 12323 -results in ---> 1. John Ham 2. 123 elm st 3. . New York 4. NY 5. 12323 ---> Link to comment Share on other sites More sharing options...
Nine Posted January 25, 2021 Share Posted January 25, 2021 Unless there is always a ending street name acronym (st - av - rd - blvd - ...), I am afraid it would be impossible to extract correctly all the times. How about apartment numbers ? And PO box ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Danp2 Posted January 25, 2021 Share Posted January 25, 2021 33 minutes ago, Nine said: Unless there is always a ending street name acronym (st - av - rd - blvd - ...), I am afraid it would be impossible to extract correctly all the times. How about apartment numbers ? And PO box ? That why I use https://github.com/datamade/usaddress to parse addresses. I have a Ubuntu VM that takes the request and returns the parsed data. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
fmendi Posted January 25, 2021 Author Share Posted January 25, 2021 (edited) I understand that there are limitless variations that cannot be covered. In this particular situation, I am going to have to manipulate the address by adding a period after the street address, if it does not already exist, before putting it through regex. Edited January 25, 2021 by fmendi Link to comment Share on other sites More sharing options...
Nine Posted January 25, 2021 Share Posted January 25, 2021 That seems to work fine if you correctly list all acronyms : #include <Constants.au3> #include <Array.au3> Local $aAddr = [ _ "Frank Conte 2133 Elm St. Gainesville, FL, 45679.", _ "Frank F. Conte 123 First Rd. New York NY, 12345.", _ "Frank Conte 2133 Elm blvd Gainesville fl, 45679.", _ "Frank Conte 2133 Elm av Gaines Town, FL, 45679"] Local $aComp For $sAddr in $aAddr $aComp = StringRegExp($sAddr, "(?si)([^\d]+)(.*(?:st|av|blvd|rd))\.?\h*(.*?),?\h*([A-Z]{2}),\h*(\d+)", 1) _ArrayDisplay($aComp) Next “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
seadoggie01 Posted January 25, 2021 Share Posted January 25, 2021 (edited) It's slightly more complicated, but the other thing you can try is to build your RegEx from a config file. Then, any time you come across an address (that doesn't work), you could have your program: Ask if there is a new acronym Add it the new acronym to the config then rebuild and retry the RegEx (Optionally) Save the address to review (and/or manually enter) later Edited January 25, 2021 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now