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

182
Vistas
Extract text until second to last occurrence from string

How do I extract the text from the beginning until (not including) the second to last occurrence of a charachter (":" in this case) from a string? Preferably without using regex.

Examples:

"urn:riv:intygsbestallning:certificate:order:RequestPerformerForAssessmentResponder:1" should become "RequestPerformerForAssessmentResponder:1"

"urn:riv:itinfra:tp:PingResponder:1" should become "PingResponder:1"

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

0

with split function you can parse your string returning an array of the tokens separated from the string in the parameter of split and later you can concatenate last two items in the array

let x = "urn:riv:intygsbestallning:certificate:order:RequestPerformerForAssessmentResponder:1";

let result = x.split(":");
let yourTextResult = `${result[result.length-2]}:${result[result.length-1]}`;
console.log(yourTextResult );

about 4 years ago · Juan Pablo Isaza Denunciar

0

const data1 = "urn:riv:intygsbestallning:certificate:order:RequestPerformerForAssessmentResponder:1";
const data2 = "urn:riv:itinfra:tp:PingResponder:1"

const arr = data1.split(':');
console.log(arr.splice(arr.length-2,arr.length).join(':'))

about 4 years ago · Juan Pablo Isaza Denunciar

0

str = 'urn:riv:intygsbestallning:certificate:order:RequestPerformerForAssessmentResponder:1'

split_array = str.split(':')
ans = split_array.splice(-2).join(':')

console.log('ans', ans)

cut_off_part = split_array.join(':') + ':'
console.log('cut_off part', cut_off_part)
    

Another way of doing the same:

str = 'urn:riv:intygsbestallning:certificate:order:RequestPerformerForAssessmentResponder:1'

ans = str.split(':').splice(-2).join(':')
console.log("answer", ans)

cutoff_part = str.substr(0, str.length - ans.length)
console.log("cut_off_part", cutoff_part)

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