i match "775" (representing last 3 digit number unkown total number of occurrences) within string "one 234 2 449 3 775 f4our" , "f4our" representing unknown number of characters (letters, digits, spaces, not 3 or more digits in row).
i came regular expression "(\d{3}).*?$" thinking "?" suffice 775 instead of 234, doesn't seem work.
is there way accomplish using vba regular expressions?
note (\d{3}).*?$
matches , captures group 1 first 3 consecutive digits , matches 0+ characters other newline end of string.
you need 3 digit chunk @ end of string not followed 3-digit chunk anywhere after it.
you may use negative lookahead (?!.*\d{3})
impose restriction on match:
\d{3}(?!.*\d{3})
see regex demo. or - if 3 digits matched whole word:
\b\d{3}\b(?!.*\b\d{3}\b)
see another demo
Comments
Post a Comment