Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: remove first and last character of string

by AnomalousMonk (Archbishop)
on Oct 14, 2020 at 17:17 UTC ( [id://11122837]=note: print w/replies, xml ) Need Help??


in reply to remove first and last character of string

As with others who have commented in this thread, it's not clear to me just what flieckster wants to achieve.

If, and it's a big if, the aim is to remove double-quotes only when they are paired at both the start and end of the string and never in any other circumstance, then
    qr{ (?| \A " (.*) " \z | (.*)) }xms  # needs 5.10+
will do the trick. With this regex,
   '""'  '""""'  '"foo"'  '"fo"o"'  '"f"o"o"'
become
    ''    '""'    'foo'    'fo"o'    'f"o"o'
respectively, while strings like
    ''  '"'  '"foo'  'foo"'  'f"oo'  'f"o"o'
are unchanged.

Note that this regex needs Perl version 5.10+ because it uses the (?|...) branch reset regex extension. The regex can be made to work in pre-5.10 versions by removing the (?|...) and adding a grep defined, ... filter to the output of the regex match.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-23 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found