Search code examples
rubyregexquotesapostrophe

select quotes but NOT apostrophes in REGEX


I would like to achieve this amazing result (I'm using Ruby):

input:  "Joe can't tell between 'large' and large."   
output: "Joe can't tell between large and large."

getting rid of the quotes but not of the apostrophe
how can I do it in a simple way?

my failed overcomplicated attempt:

 entry = test[0].gsub(/[[']*1]/, "")

Solution

  • Simplest one for your situation could be something like this.

    Regex: /\s'|'\s/ and replace with a space.

    Regex101 Demo


    You can also go with /(['"])([A-Za-z]+)\1/ and replace with \2 i.e second captured group.

    Regex101 Demo