Using a regular expression (replaceregexp in Ant) how can I match (and then replace) everything from the start of a line, up to and including the last occurrence of a slash?
What you want to do is match greedily, the longest possible match of the pattern, it is default usually, but match till the last instance of '/'.
That would be something like this:
.*\/
Explanation:
. any character
* any and all characters after that (greedy)
\/ the slash escaped, this will stop at the **last** instance of '/'
You can see it in action here: http://regex101.com/r/pI4lR5
You can match this:
.*\/
and replace with your text.
DEMO
Option 1
^.*/
Empty string
*
quantifier is greedy, ^.*/
will match from the start of the line to the very last slash. So you can directly replace that with an empty string, and you are left with your desired text.Option 2
^.*/(.*)
$1
or \1
, not sure about Ant)^.*/
matches to the last slash. You then capture the end of the line to Group 1 with (.*)
, and replace the whole match with Group 1.