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
 

DonManfred

Expert
Licensed User
Longtime User
i would use the second (creating a new matcher each time)
 
Upvote 0
Top