Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: remove chars with regex

by johngg (Canon)
on Feb 26, 2025 at 11:05 UTC ( [id://11164091]=note: print w/replies, xml ) Need Help??


in reply to remove chars with regex

An alternative to using a regex is substr applied at either end of the string.

johngg@aleatico:~$ perl -Mstrict -Mwarnings -E 'say q{}; my $char = q{0x388c818ca8b9251b393131c08a736a67ccb19297}; say join q{ ... }, substr( $char, 0, 6 ), substr( $char, length( $char ) - 6, 6 );' 0x388c ... b19297

I hope this is helpful.

Update: Re. AnonyMonk's comment regarding negative offsets, I had completely forgotten that, how dumb am I :-(

Update 2: Here's the amended code.

johngg@aleatico:~$ perl -Mstrict -Mwarnings -E 'say q{}; my $char = q{0x388c818ca8b9251b393131c08a736a67ccb19297}; say join q{ ... }, substr( $char, 0, 6 ), substr( $char, -6 );' 0x388c ... b19297

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: remove chars with regex
by Anonymous Monk on Feb 26, 2025 at 15:32 UTC

    FWIW, the second substr ... (for the last 6 characters) could be substr( $char, -6 ). Negative offsets are from the end, and if you omit the length you get all of the string after the start position.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2025-11-09 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (65 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.