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

164
Vistas
Matching three underscore strings at the start of end of non-whitespace text chunks depending on immediate context

In all cases listed below, I want to match only ___ (three underscores).

To make it clear, I am trying to match 3 underscores either not immediately preceded or not immediately followed with an underscore character and:

  • if a character other than whitespace and _ precedes the ___, match last 3 (test3____)
  • if a character other than whitespace and _ follows the ___, match first 3 (_______test5).

See my current attempt:

((?<=_)___|___(?=_)|___)

Tested with:

test1___(test2 ___)
   test3____ ___
  ___test4 + ____test5

All cases are matching correctly except for "test3": it matches first 3 underscores instead of the last 3.

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

0

You can use

(?<!_)___(?=_*[^\s_])|(?<=[^\s_]_*)___(?!_)|(?<!_)___(?!_)

See the regex demo. Details:

  • (?<!_)___(?=_*[^\s_]) - a ___ string not immediately preceded with a _ char and that is immediately followed with any zero or more underscores and then any char other than whitespace and _
  • | - or
  • (?<=[^\s_]_*)___(?!_) - a ___ string that is not immediately followed with another _ char and immediately preceded with any char other than whitespace and _ and then any zero or more underscores
  • | - or
  • (?<!_)___(?!_) - three underscores neither preceded nor followed with another _ char.
about 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