I’ve gotten fairly decent with Regex, but this one eludes me. I want my search pattern to be between one character, and then the LAST occurrence of the another character.
In the example below, it will stop at the FIRST occurrence of > once it passes the first occurrence of <. I want the pattern to be between the first occurrence of <, and the LAST occurrence of the >. Any ideas? This would be a big help for now an in the future for me. Thanks!
Dim rg3 as New RegEx
rg3.SearchPattern=<(.*)>
rg3.Options.Greedy = False
rg3.Options.DotMatchAll = True
Dim myMatch3 as RegExMatch = rg3.search(cellname)
if myMatch3 <> nil then
VALUE = trim(myMatch3.SubExpressionString( 1 ))
else
end
That was it! Never looked into what Greedy did exactly, so whatever I thought it did wasn’t what you just pointed out. Never would have guessed it had anything to do with that…always figured it would be something with the syntax of the search pattern line.
Greed false, basically means “stop as soon as something satisfies the search”, Greed true means, “keep going, stop when the search is completely satisfied”. So having the string "000 < aaa > bbb> ccc> 999" and searching a not greed "<.*>" you’ll get “000 < aaa > bbb> ccc> 999”, but greed true you’ll get “000 < aaa > bbb> ccc> 999”
I still think it satisfies the OP’s original question, and yes, in that example it would match the entire string but because of the substring request, leave off the first and last characters. I still can’t think of a string where it would NOT satisfy the OP’s original question. Can you give an example where it would fail? I can’t; which is what I meant by maybe I don’t understand what greedy = true would do in that context. I don’t see how it would fail.
Wouldn’t that require there to be text ahead of the first < and after the final > character? The OP did not state that as a requirement. As I interpret the OP, even Greg’s sample which matches the entire input string (other than using a subexpression) still meets the OP’s request.