Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

347
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda