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

343
Vistas
Ruby regex anchors combined with character class &&

I am trying to match a string containing printable ascii without some special characters, for example the character 'x'. I use this regex /[.&&[^x]]/ for this task.

When trying to match if the whole string is made from this character specification the regex doesn't match any more. /^[.&&[^x]]*$/

Trying this with the normal dot works however. /^.*$/ matches every string i throw at it.

I'm using Ruby 2.7.2

The regex is constructed at runtime and the /^ ... $/ anchors are needed for other edge cases.

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

0

Printable ASCII regex is [ -~].

To match any printable ASCII char other than x, just use character class subtraction on this class: [ -~&&[^x]].

To match a string that only contains such chars use

/\A[ -~&&[^x]]*\z/

See the Rubular demo.

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