+ Reply to Thread
Results 1 to 7 of 7

RegEx Backreference

  1. #1
    Registered User
    Join Date
    01-26-2015
    Location
    Massachusetts
    MS-Off Ver
    2016
    Posts
    73

    RegEx Backreference

    Hello Everyone,

    I almost have this working. I'm trying to find those street number suffixes that should be appearing like this 5th Avenue but are appearing with the first letter capitalized like this: 5Th

    I'm using this snippet of regular expression which is working:


    FIXNUMBERSUFFIX = strLookIn

    objRegEx.Pattern = "\b([0-9])(Th)\b"
    FIXNUMBERSUFFIX = objRegEx.Replace(FIXNUMBERSUFFIX, "$1" & "th")


    It's correctly finding and changing this address 520 W. 5Th Street, Apt. 500 to this: 520 W. 5th Street, Apt. 500

    Then is I realized I have to account for up to three digit street numbers. I tried the following, but it's not working. I must not have the correct expression for finding a three digit pattern. Also don't know how to reference back to it.

    objRegEx.Pattern = "\b([1-9][1-9][0-9])(Th)\b"
    FIXNUMBERSUFFIX = objRegEx.Replace(FIXNUMBERSUFFIX, "$1$2$3" & "th")

    Thank you for your help!

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: RegEx Backreference


    Hi !

    Ever no need a regular expression but just using easy Replace VBA function !

  3. #3
    Registered User
    Join Date
    01-26-2015
    Location
    Massachusetts
    MS-Off Ver
    2016
    Posts
    73

    Re: RegEx Backreference

    Thanks Marc. But I don't know how many numbers will appear before each incorrect suffix. And I can't replace all instances of Th for th because Th could be at the beginning of another word. Thames Street. etc.
    Last edited by wwconslt; 02-20-2017 at 10:32 PM.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool


    No ! Just warming a couple of neurons ‼

    At kid level : just replace "Th " by "th " and that's all folks !
    Last edited by Marc L; 02-20-2017 at 10:46 PM.

  5. #5
    Registered User
    Join Date
    01-26-2015
    Location
    Massachusetts
    MS-Off Ver
    2016
    Posts
    73

    Re: RegEx Backreference

    I think I have it. I had to add the asterisk after the [0-9]* which I believe means 0 or more matches?

    objRegEx.Pattern = "\b([0-9]*)(Th)\b"
    FIXNUMBERSUFFIX = objRegEx.Replace(FIXNUMBERSUFFIX, "$1" & "th")

    Thank you.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: RegEx Backreference


    Do you really need an Abrams tank to just knock a door ?‼

    PHP Code: 
    Sub Demo4Noob()
        
    MsgBox Replace$("5TH Street""TH ""th ")
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: RegEx Backreference

    Hi,

    If you know it's 1-3 matches, you can also use ([0-9]{1,3})
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ 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. RegEx not getting expression
    By amartinez988 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-01-2015, 11:14 AM
  2. RegEx pattern
    By capson in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 02-15-2015, 06:57 PM
  3. COUNTIF using regex
    By Sathed in forum Excel General
    Replies: 3
    Last Post: 07-07-2014, 02:31 PM
  4. Not able to use the regex in code...
    By lifeankit in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-22-2014, 06:54 AM
  5. [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
  6. RegEx Problem
    By Marshall80 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2011, 04:49 AM
  7. Excel regex
    By f3tus in forum Excel General
    Replies: 1
    Last Post: 06-05-2010, 06:50 AM

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