Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to remove everything after last occurrence of a string?

by tybalt89 (Monsignor)
on Jun 06, 2022 at 16:11 UTC ( [id://11144454]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144454]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-24 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found