+ Reply to Thread
Results 1 to 11 of 11

Use More then one Regex to determine a a name

  1. #1
    Registered User
    Join Date
    01-18-2018
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    17

    Use More then one Regex to determine a a name

    Hi ,

    Say i have 4 columns in an excel sheet .the first is the input column, the second column contains multiple regex definitions, the third column contains a predefined string and the fourth column contains the data entered by the user in a the predefined way.

    So what im trying to figure out is when a user enters in data in the first column , a macro or formula will look at all the regex expressions and match with the most relevant one. and display the entered text in the correct format.

    Thanks
    Attached Files Attached Files
    Last edited by AbertBean; 01-21-2018 at 07:15 PM.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Use More then one Regex to determine a a name

    Please post your workbook with several examples of what you are expecting
    To attach workbook
    - GoAdvanced \ scroll down \ ManageAttachments \ follow screen instructions
    Thanks
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    01-18-2018
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    17

    Re: Use More then one Regex to determine a a name

    I have added an attachement

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,557

    Re: Use More then one Regex to determine a a name

    I feel that in order to attempt to help we need to see some examples of possible inputs and expected outputs.
    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Registered User
    Join Date
    01-18-2018
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    17

    Re: Use More then one Regex to determine a a name

    I have added examples
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Use More then one Regex to determine a a name

    The file attached to post#5 appears to be damaged (my) Excel refuses to read it
    Before you re-attach it, could you add an extra field and "rank" the RegEx pattern column (from 1 to 5) based on the following criteria to allow rules to be written to allow VBA to make decisions
    Clearly some of the patterns are guaranteed to yield the correct result every time if a match is found, but other (less onerous patterns) could result in a lot of "false positives"

    Criteria
    1 = if string matches ASSUME correct (the searched for string is too specific to be anything else)
    2 = if string matches ASSUME correct (based on knowledge of data structure)
    3 = if string matches PROBABLY correct (quite a specific string)
    4 = if string matches PROBABLY correct (based on knowledge of data structure)
    5 = everything else

    Thanks

  7. #7
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Use More then one Regex to determine a a name

    maybe this one will be readable (just testing)

  8. #8
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Use More then one Regex to determine a a name

    yes it's readable @sandy666 - thanks

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Use More then one Regex to determine a a name

    Attached is workbook to get this going
    - to make things easier to visualise everything is written to the worksheet rather than using arrays
    - after testing is complete (depending on performance etc) that may need to change

    Workbook contains 3 sheets - TestRegex, Workings & OriginalData

    Workings:
    - Note user defined function used as formula in column E
    - Column C used to give me some TRUE matches to RegEx pattern

    TestRegex:
    Button Run RegEx Check runs macro
    - checking each value in column B against each "Pattern" held in row 3
    - TRUE returned if match found, blank otherwise
    - column A returns count of matches found for each value
    - some test data retained for you to look at before testing yourself

    To test
    - click on Clear Old Data
    - paste values into column B
    (pasting only the values will maintain the pretty blue font )

    Moving forward:
    There are clearly going to be multiple matches for some values, so we need some way to alow VBA to choose likely best choice
    After testing with your real data you should be able to come up with a ranking structure to try to avoid some of the false positives
    This is my suggestion:
    Criteria
    1 = if string matches ASSUME correct (the searched for string is too specific to be anything else)
    2 = if string matches ASSUME correct (based on knowledge of data structure)
    3 = if string matches PROBABLY correct (quite a specific string)
    4 = if string matches PROBABLY correct (based on knowledge of data structure)
    5 = everything else

    To make it easier to develop the next bit of code, please re-attach the workbook with
    - your rankings entered in column A on sheet "Workings"
    AND
    - a lot of typical varied data in column B on sheet "TestRegEx" (1000 rows? perhaps)
    (NB file size should be below 1 meg)

  10. #10
    Registered User
    Join Date
    01-18-2018
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    17

    Re: Use More then one Regex to determine a a name

    Please find attached updated excel workbook

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Use More then one Regex to determine a a name

    Thanks for the workbook
    - will look tomorrow or Sunday

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] help with a function using Regex
    By Pancho3 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-24-2016, 09:22 PM
  2. RegEx pattern
    By capson in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 02-15-2015, 06:57 PM
  3. [SOLVED] How to REGex with VBA words
    By Odeen in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 12-03-2012, 09:12 AM
  4. RegEx Problem
    By Marshall80 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2011, 04:49 AM
  5. Excel regex
    By f3tus in forum Excel General
    Replies: 1
    Last Post: 06-05-2010, 06:50 AM
  6. [SOLVED] RegEx to parse something like this...
    By R Avery in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2005, 07:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1