Add replaceAll and replaceFirst#19070
Conversation
|
Why not use the official loop for replacements in Matcher? https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html#appendReplacement-java.lang.StringBuffer-java.lang.String- |
|
I don't know enough about java's regex to know if Uwe's suggestion is strictly equivalent. But I like the PR. |
I figured those were less than desirable because they were StringBuffer instead of StringBuilder. |
That's not an issue anymore. StringBuilder and StringBuffer are as fast in Java 6+. The introduction of StringBuilder was only needed in older Java versions. This is the reason why the APIs of Matcher were not changed afterwards (issues in OpenJDK closed). So please don't reimplement the code and be safe and use the Matcher methods! If you look at In addition, the Java APIs allow to use |
Looks like it. Uncontended synchronization elimination works as expected. Another old habit gone.
I'll look into it. |
And done. It seems silly that they didn't make |
|
Thanks. Shouldn't we maybe allow |
|
Not for the closure form. You can get them from the matcher. You can
|
|
My reasoning is that |
|
@nik9000 i want to be able to do things like: I have no idea what this would look like with your syntax? |
That is already there with us whitelisting This proposed syntax if for when you need to manipulate the captures more than just moving them around. |
I think it would be confusing to diverge from that behavior. For a lot of reasons consistency with whatever it is doing will be easiest on everyone if we can have it. |
|
@clintongormley I can add another example to the docs calling out |
I just added that to this PR. |
|
What is the status here? this change looks good to me. |
I'm not sure.... I think at this point I'll merge it and we can rework it later if it needs it? |
These are useful methods in groovy that give you control over the replacements used: ``` 'the quick brown fox'.replaceAll(/[aeiou]/, m -> m.group().toUpperCase(Locale.ROOT)) ```
a0ed47d to
67bfecc
Compare
These are useful methods in groovy that give you control over
the replacements used:
They mimick two of the augments groovy has for regexes.