Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
Break string into words using scan method + regexp, if word has `'` character, drop this character and everything after it
sample_string = "let's could've they'll you're won't"
sample_string.scan(/\w+/)

Above gives me:

["let", "s", "could", "ve", "they", "ll", "you", "re", "won", "t"]

What I want:

["let", "could", "they", "you", "won"]

Been playing around in https://rubular.com/ and trying assertions like \w+(?<=') but no luck.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Given:

> sample_string = "let's could've they'll you're won't"

You can do split and map:

> sample_string.split.map{|w| w.split(/'/)[0]}
=> ["let", "could", "they", "you", "won"]
over 4 years ago · Santiago Trujillo Denunciar

0

You can use

sample_string.scan(/(?<![\w'])\w+/)
sample_string.scan(/\b(?<!')\w+/)

See the Rubular demo. The patterns (they are absolute synonyms) match

  • (?<![\w']) - a location in the string that is not immediately preceded with a word or ' char
  • \b(?<!') - a word boundary position which is not immediately preceded with a ' char
  • \w+ - one or more word chars.

See the Ruby demo:

sample_string = "let's could've they'll you're won't"
p sample_string.scan(/(?<![\w'])\w+/)
# => ["let", "could", "they", "you", "won"]
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda