Jump to content
Sign in to follow this  
saywell

Quick RegEx question

Recommended Posts

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

Share this post


Link to post
Share on other sites

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


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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! :P


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...