regexperl

How to trim a certain part of a string?


I have this value stored in a string:

"-rw-rw-r--  1 xyz test   3.7K Mar 25 14:59 abcd.txt".

And I just want to trim the "abcd.txt" part from the string into another.

NB - rest of the part is not constant.


Solution

  • my ($trimmed) = $string =~ /(\S+)$/;
    

    although you might be better with using ie. glob("*txt") rather than fiddling with external ls.

    perldoc -f glob