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

588
Visualizações
RegEx for no whitespace at the beginning and end but allows all special characters , spaces , lowercase and uppercase alphabet and numbers in between

I wanted to design an regex for not allowing whitespace at the beginning and at the end of a string, but allows all special characters , spaces , lowercase and uppercase alphabets and numbers in between

The regex I tried is :

'^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$'

I am using it as a pattern validator inside input in angular as : pattern ="^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$'"

anyhelp would be greatly appreciated

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

All the ASCII alphabets and special characters are defined with [!-\[\]-~]

By making sure the first and optional last is this class is all that's needed.

^[!-\[\]-~]+(?:[^\S\r\n]*[!-\[\]-~])*$

https://regex101.com/r/JpsOvy/1

 ^ 
 [!-\[\]-~]+ 
 (?: [^\S\r\n]* [!-\[\]-~] )*
 $

[^\S\r\n] is just non-linefeed white space. Replace with \s if needed.

about 4 years ago · Juan Pablo Isaza Relatório

0

You need either

Validators.pattern('\\S(?:.*\\S)?')

Or

Validators.pattern(/^\S(?:.*\S)?$/)

In both cases, the regex is ^\S(?:.*\S)?$ and matches

  • ^ - start of string
  • \S - any char other than whitespace
  • (?:.*\S)? - an optional occurrence of any zero or more chars other than line break chars as many as possible and then a non-whitespace char
  • $ - end of string.
about 4 years ago · Juan Pablo Isaza 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