Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Removing characters in a file name

by Anonymous Monk
on Apr 23, 2020 at 18:21 UTC ( #11115965=note: print w/replies, xml ) Need Help??


in reply to Removing characters in a file name

The OP does not make it clear, but it superficially appears that the element of interest in the filename appears only to be a sequence of digits surrounded by whitespace:

/[A-Za-z0-9]+.*\b([0-9]+)\b/

Should be easy enough to rename them, but it might be advisable to accumulate a hash-list of the renames that need to be made first, then to perform all renames separately. (The regex above thus excludes names that consist only of digits.)

Replies are listed 'Best First'.
Re^2: Removing characters in a file name
by haukex (Bishop) on Apr 23, 2020 at 20:01 UTC
    a sequence of digits surrounded by whitespace: /[A-Za-z0-9]+.*\b([0-9]+)\b/

    No. That regex doesn't require whitespace anywhere.

    The regex above thus excludes names that consist only of digits.

    Since it's not anchored, it'll match anywhere in the filename, including its extension; only if you have files whose names are literally just digits, without an extension, it won't match. It'll also match two digits separated by a non-word (as well as non-whitespace) character.

    WebPerl Regex Tester Link

    Edit: Improved wording in second paragraph.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2020-09-19 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (114 votes). Check out past polls.

    Notices?