Remove part of a string

This example will show how to remove part of a string in groovy. The minus() method will remove part of a string which matches the parameter which can be either a String or a regular expression. The same operation can also be performed with the minus operator as shown in the second snippet.

Using minus

@Test
void remove_part_of_string_minus() {

    def part = "hit the ground running"

    assert "hit the ground" == part.minus(" running")
}

Using - operator

@Test
void remove_part_of_string_operator() {

    def part = "hit the ground running"

    assert "hit the ground" == part - " running"
}