in reply to How to remove everything after last occurrence of a string?
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11144451 use warnings; my ($path,$version); $path = "/a/b/version1/c/d"; $version = "version1"; $path =~ s/.*\Q$version\E\K.*//s; print($path."\n"); $path = "/some/path/3.5.2+tcl-tk-8.5.18+sqlite-3.10.0/a/b/c"; $version = "3.5.2+tcl-tk-8.5.18+sqlite-3.10.0"; $path =~ s/.*\Q$version\E\K.*//s; print($path."\n");
Outputs:
/a/b/version1 /some/path/3.5.2+tcl-tk-8.5.18+sqlite-3.10.0
|
|---|