Friday, 6 April 2018

regex - String search Regular expressions VB?

In Excel VB I'm trying to search a string for a 4 digit number denoting a year, ie. "The man was born in the year 1986, it was a sunny day", I am trying to extract the "1986" from this string. It seems like using regular expressions would be my best option however I'm unfamiliar with them, is the regular expression for a 4 digit number something like "\d{4}" ?,



if I find that my string contains such a number is there an efficient way for getting the start and end point of the string for extraction? I have ideas on how to do it but they seem very inefficient, is there a fast way to find and extract this data?



pseudocode:



dim bool As boolean

bool = cells(d, 1).Value.contains(\d{4})

if bool then
'extract string
end if

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...