Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Remove double bracket and singe quotes

by wee (Scribe)
on May 02, 2016 at 19:59 UTC ( [id://1162040]=note: print w/replies, xml ) Need Help??


in reply to Remove double bracket and singe quotes

This works for me:
#!/usr/bin/perl use 5.010; use strict; use warnings; my $doc = "'C-3PO' or 'See-Threepio' is a humanoid robot character fro +m the [[Star Wars]] universe who appears in the original ''Star Wars' +' films, the prequel trilogy and the sequel trilogy."; $doc =~ s/[\[\]']+//g; say $doc;
Did you mean that you want to only remove one single quote and not two of them?

Replies are listed 'Best First'.
Re^2: Remove double bracket and singe quotes
by smknjoe (Beadle) on May 04, 2016 at 18:38 UTC
    I like how the OP hasn't come back to clarify his problem and qualify what "Doesn't work at all" really means.

    But, I think the answer to your question is "yes"; only a single quote and not double quotes. Which then begs the question (from me) HOW DO YOU do this? As soon as you put a single quote followed by the "g" option on the search-and-replace, it removes all of them.
      $doc =~ s/(?<!\')\'(?!\')//g;

      The above seems to work for OP's example. Only matches single "'" by using negative look-behind and negative look-ahead assertions to avoid matches of more than one consecutive single quote.

        Excellent! I've never had a need to use look-ahead/look-behind in any of my scripts, so this is new territory for me.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 21:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found