Something I've been wanting to do for a while is provide complete example coverage for methods defined on regexp.Regex. There are 36 methods, 11 of which have examples. Unless this isn't desired, I'd like to finish the other 25.
All yours @shoenig, thank you!
I'm not sure that's a good idea. The methods are all variations on the same scheme. I don't see how enumerating the possible combinations and generating examples for them adds significant value over what's already there.
Please don't expand the docs with content that basically amounts to filler material just to satisfy some notion of exhaustiveness. If it's part of the docs, it should be worth to read. Excessive repetition is a time waster for people learning the API of a package.
If you can pull it off to demonstrate a new aspect of the package with every added example, go wild though!
Change https://golang.org/cl/120145 mentions this issue: regexp: add more examples for Regexp methods
Change https://golang.org/cl/142197 mentions this issue: regexp: add examples for regexp functions
Thank you @cn007b for adding more examples. Here are some remaining ones for which I think examples would be good to have to keep it consistent with the other examples.
I think once these are done, we can close this bug. The remaining ones are just simple variants of other methods which already have examples.
@agnivade I created a PR for it. I didn't add an example for Regexp.Longest(). I think that is the default behavior for the RE module and I can't find a function to unset it.
It's not the default. https://tip.golang.org/pkg/regexp/#Compile is leftmost-first. https://tip.golang.org/pkg/regexp/#CompilePOSIX is the one which is leftmost-longest.
Change https://golang.org/cl/189137 mentions this issue: regexp: add example for ReplaceAll
Change https://golang.org/cl/189138 mentions this issue: regexp: add example for NumSubexp
Change https://golang.org/cl/189177 mentions this issue: regexp: add examples for FindSubmatchIndex, FindAllIndex and Longest
@agnivade #33489 #33497 #33490 cover all 5 missing examples
All of the examples that I outlined have been submitted. I will go ahead and close this now. Thank you everyone who contributed to the examples.
Most helpful comment
I'm not sure that's a good idea. The methods are all variations on the same scheme. I don't see how enumerating the possible combinations and generating examples for them adds significant value over what's already there.
Please don't expand the docs with content that basically amounts to filler material just to satisfy some notion of exhaustiveness. If it's part of the docs, it should be worth to read. Excessive repetition is a time waster for people learning the API of a package.
If you can pull it off to demonstrate a new aspect of the package with every added example, go wild though!