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

166
Vistas
Regex to get parts of a string

all i am struggling to get sections of a string with regex without using Split or any other similar function here is my scenario:

I have this text U:BCCNT.3;GOwhich i want to get the different sections divided but the symbols in the middle I have managed to get the first one with this regex /(.+):/.exec(value) this gives me the first word till the colon(:) and these are the different variations of the value

Second section BCCNT

BCCNT.3;GO -> without the U: so the string might also contain no colon so for the second section the logic would be any text that is between : and . or any text ending with . and nothing infront

Third section .3-> any text starting with a . and ending with nothing or anytext staring with a . and ending with a ; semicolon

Fourth section ;GO-> any text starting with a ; and ending with nothing

EDIT and preferably on separate variables like

const sectionOne = regex.exec(value);
const sectionTwo = regex.exec(value);
const sectionThree = regex.exec(value);
const sectionFour = regex.exec(value);

and which ever value doesnt match the pattern the variable would just be undefined or null or any empty string

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Here is a regex approach using 4 separate optional capture groups for each possible component:

var input = "U:BCCNT.3;GO";
var re = /^([^:]+:)?([^.]+)?(\.[^;]+)?(;.*)?$/g;
var m;

m = re.exec(input);
if (m) {
    console.log(m[1], m[2], m[3], m[4]);
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

Something like

/^(?:([^:]*):)?([^.]*)\.(?:([^;]*);(.*))?/

For example:

const s = 'U:BCCNT.3;GO';
const m = s.match(/^(?:([^:]*):)?([^.]*)\.(?:([^;]*);(.*))?/);

console.log(m);

about 4 years ago · Juan Pablo Isaza 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