saywell Posted March 11, 2011 Posted March 11, 2011 Hi,I'm trying to pick out 6-digit numbers from a string.(\d{6,6}) works, but it includes numbers of more than 6 digits, and also 6-digit numbers with a prefix, neither of which do I want.Could one of you RegEx gurus point me in the right direction to limit the start to the beginning of a 'word' and the whole thing to match 6 and 6 only consecutive digits?I've tried playing with /b -- (\(\d{6}) but that gives a load of blank returns in between the correct ones, though it filters the numbers with a digit prefix OK.Regards,William
Moderators Melba23 Posted March 11, 2011 Moderators Posted March 11, 2011 saywell, It is always easier if you can give a few samples with the required output. Otherwise we risk producing an SRE which does not do exactly what you want and we have to start all over again. As I age considerably each time I try to write one I would prefer to do it as little as possible. 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
saywell Posted March 11, 2011 Author Posted March 11, 2011 OK, it's the agenda from a medical meeting, which starts as a word doc [table] and is copied to a string as per the attached text file [anonymised]. I need to get all the stand-alone 6 digit numbers - excluding components of the YH-prefixed 8-digit number, or indeed any other numbers with a letter prefix, and any that aren't exactly 6 digits long. If I load the file into PCRE Toolkit and use (\(\d{6}) it gives all the correct matches, and no incorrect matches apart from null strings [which faut de mieux I could take out of the array using non regex techniques]. William
Moderators Melba23 Posted March 11, 2011 Moderators Posted March 11, 2011 saywell, This works for me: #include <Array.au3> $sText = FileRead("test.txt") $aArray = StringRegExp($sText, "\s(\d{6})\s", 3) _ArrayDisplay($aArray) Explanation: \s = any horizontal whitespace (\d{6}) = match any six digit sequence \s = any horizontal whitespace Does it work for you too? M23 P.S. Not as much as an extra grey hair - I must be getting better at SREs! 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
saywell Posted March 11, 2011 Author Posted March 11, 2011 Yup - works for me too!! Thanks for your help - again! William
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