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

184
Vistas
Regex to avoid specific content

I have a string like 23DGERA@SPK_20W L+R FA-2@1+342HSHC@CPU_8PIN INTEL_TEST!@1+2356GHMX@SSD_256G MICRON_CONTENT@2 + blablabla.

What I would like to do is to split up the string by +, yet in SPK section there is a L+R that would interrupt the process. Is there any REGEX that could achieve what I want?

In result should be:

23DGERA@SPK_20W L+R FA-2@1
342HSHC@CPU_8PIN INTEL_TEST!@2
2356GHMX@SSD_256G MICRON_CONTENT@2

and now what i always get:

23DGERA@SPK_20W L
R FA-2@1
342HSHC@CPU_8PIN INTEL_TEST!@2
2356GHMX@SSD_256G MICRON_CONTENT@2

I'm using Javascript .split('+') by now.

Any help will be appretiated.

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

0

You can use a matching regex solution:

text.match(/(?:L\+R|[^+])+/g)

See the regex demo. Details:

  • (?: - start of a non-capturing group:
    • L\+R - L+R string
    • | - or
    • [^+] - any char other than +
  • )+ - end of the group, one or more occurrences.

See the JavaScript demo:

var text = '23DGERA@SPK_20W L+R FA-2@1+342HSHC@CPU_8PIN INTEL_TEST!@1+2356GHMX@SSD_256G MICRON_CONTENT@2';
console.log(text.match(/(?:L\+R|[^+])+/g));

ECMAScript 2018+ compliant solution

In case you want to migrate to a more modern ECMAScript flavor, you can use

text.split(/\+(?<!L\+(?=R))/)

This will match a + that is not part of an L+R string.

const text = '23DGERA@SPK_20W L+R FA-2@1+342HSHC@CPU_8PIN INTEL_TEST!@1+2356GHMX@SSD_256G MICRON_CONTENT@2';
console.log(text.split(/\+(?<!L\+(?=R))/));

See the regex demo.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of splitting on a + you could match the format in the example data.

First match a part containing a single @, and then match till the first occurrence of @ followed by a digit.

Note that the second match will be 342HSHC@CPU_8PIN INTEL_TEST!@1 instead of 342HSHC@CPU_8PIN INTEL_TEST!@2

\w+@\w+ [^@]*@\d\b

The pattern matches:

  • \w+@\w+ Match 1+ word characters, @ and at 1+ word characters
  • [^@]*@ Match a space, optional chars other than @, then match @
  • \d\b Match a digit and a word boundary to prevent a partial match

Regex demo

const s = "23DGERA@SPK_20W L+R FA-2@1+342HSHC@CPU_8PIN INTEL_TEST!@1+2356GHMX@SSD_256G MICRON_CONTENT@2 + blablabla";
const regex = /\w+@\w+ [^@]*@\d\b/g;
console.log(s.match(regex));

about 4 years ago · Juan Pablo Isaza Denunciar

0

The string looks like a list of parts each with a quantity e.g. @1. You can use that to identify the correct + characters to split on.

Using a look-behind containing @\d+ -> (?<=@\d+) followed by the character you want to match (escaped because + has a special meaning) gives:

(?<=@\d+)\+

Using this in code we also need specify the g modifier to match all instances instead of just the first one.

const str =  '23DGERA@SPK_20W L+R FA-2@1+342HSHC@CPU_8PIN INTEL_TEST!@1+2356GHMX@SSD_256G MICRON_CONTENT@2'
const items = str.split(/(?<=@\d+)\+/g);

console.log(items);

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