Android Question Reusing the Matcher - Good idea?

Fusseldieb

Active Member
Licensed User
Longtime User
Hi there,
I have a rather simple question.
It's a good idea/programming practice to reuse a Matcher Object?

I mean following:
If I want to find two distinct things with regex I can use:
B4X:
Dim M1 As Matcher
            M1 = Regex.Matcher("some_regex.*?<\/", fullText)
            Do While M1.Find
                [...]
            Loop

Dim M2 As Matcher
            M2 = Regex.Matcher("some_other_regex.*?<\/", fullText)
            Do While M2.Find
                [...]
            Loop

Now, I've used following too and it worked just fine:
B4X:
Dim M1 As Matcher
            M1 = Regex.Matcher("some_regex.*?<\/", fullText)
            Do While M1.Find
                [...]
            Loop

            M1 = Regex.Matcher("some_other_regex.*?<\/", fullText)
            Do While M1.Find
                [...]
            Loop

Both work, but which is right way to do it?

Thanks in advance
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…