Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Duplicate
-
None
-
None
-
None
Description
Collection implements a method with the following signature:
public Object findResult(Closure closure)
It would be nice if a similar method existed for String.
public Object findResult(Pattern pattern, Closure closure)
The method find() almost performs the same function except that it converts the result to a string, even if it's null or a Boolean. Alternatively, the existing find() methods could be changed to return Object instead of String. Without this method, the matching string has to be saved into a temporary variable and then processed afterwards.
Example:
if (new File("file").text.findResult(~/VAR\s*=\s*(\S+)/)
) {
// ...
}