+ Reply to Thread
Results 1 to 13 of 13

Morefunc REGEX.FIND

  1. #1
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Morefunc REGEX.FIND

    In relation to thread: http://www.excelforum.com/excel-prog...wildcards.html and my very first question...

    First let me start off by stating as clearly as possible that this thread is concerned solely with the creation of a Regular Expression Pattern ... I am not looking for "alternative" non-REGEX methods.

    What I want to do is build a REGEX pattern that will establish as to whether or not a string matching a specified pattern can be found in another cell... the string rules are such:

    Please Login or Register  to view this content.
    Thus far I came up with the below (where A1 holds string of interest)

    =REGEX.FIND(A1,"(30[0-9]{4}-[0-9]{2})")

    Now this is all fine up to the point of the last character... ie the variable 10th Char... given it may or may not exist and where it does it may or may not be numeric.

    I need to work out how to alter the Expression to look for a numeric 10th Char but only where Char 10 exists... ie if I change the {2} to {3} in the Expression that FIND will fail as you would expect whereas in reality if Chars 8 & 9 are numeric and no Char 10 exists the FIND should return 1 given it is a valid "ending" for the string in question...

    Sample values for which REGEX.FIND should return 0

    Please Login or Register  to view this content.
    Sample values for which REGEX.FIND should return 1

    Please Login or Register  to view this content.
    I guess I "could" cheat and alter the source String if < 10 chars and append a 0 to the end, ie:

    =REGEX.FIND(A1&IF(LEN(A1)<10,0,""),"(30[0-9]{4}-[0-9]{3})")

    but I'm guessing there must be a way of doing this using the pattern itself... I'm keen to learn!

    TIA
    The Donkey
    Last edited by DonkeyOte; 06-23-2009 at 01:03 PM. Reason: surplus parentheses!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Morefunc REGEX.FIND

    I don't use MoreFunc, but maybe "(30[0-9]{4}-[0-9]{2,3})"
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Morefunc REGEX.FIND

    Thanks shg, but that doesn't (seemingly) cater for those ending say: ##@

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Morefunc REGEX.FIND

    How about?

    =REGEX.FIND(A1,"(30[0-9]{4}-[0-9]{2}[0-9]{1})")
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Morefunc REGEX.FIND

    Sorry... that doesn't work with sample 1

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Morefunc REGEX.FIND

    In post#1 you said
    Chars 8-9/8-10: must be numeric (where 10 Chars present)
    Then you said
    ie the variable 10th Char... given it may or may not exist and where it does it may or may not be numeric.
    Clarify?

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Morefunc REGEX.FIND

    Maybe then?

    =REGEX.FIND(A1&" ","(30[0-9]{4}-[0-9]{2}[^a-z,A-Z]{1})")

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Morefunc REGEX.FIND

    I had hoped the samples would have clarified my poor narrative... basically what I meant was - in relation to the last part of the pattern:

    if the string is of 10 chars in length in addition the last three chars must be numeric
    if the string is of 9 chars in length the last two chars must be numeric

    the issue with the {2,3} approach is where you have a 10 char string ending with ##@, ie:

    301234-12X

    the {2} will match even though the {3} does not.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Morefunc REGEX.FIND

    With the prior question still pending, clamp to entire string:

    ^(30\d{4}-\d{2,3})$

    EDIT: This is responsive to your last post

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Morefunc REGEX.FIND

    Quote Originally Posted by NBVC
    =REGEX.FIND(A1&" ","(30[0-9]{4}-[0-9]{2}[^a-z,A-Z]{1})")
    Yes that would do it I think... though I'd perhaps be lazy and set to non case sensitive

    =REGEX.FIND(A1&" ","(30[0-9]{4}-[0-9]{2}[^A-Z]{1})",,FALSE)

    What is the key for any non-numeric (ie instead of A-Z) - presumably there is one ?

    Thanks again all... the learning continues.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Morefunc REGEX.FIND

    [^0-9] or \D

    See also my prior post.

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Morefunc REGEX.FIND

    Quote Originally Posted by shg View Post
    ^(30\d{4}-\d{2,3})$
    This works also - no surprise there ... back to the books

  13. #13
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Morefunc REGEX.FIND

    Quote Originally Posted by DonkeyOte View Post
    This works also - no surprise there ... back to the books
    I am pretty much the same when it comes to regex... I learn on as needed basis and accumulate from there...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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