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

282
Visualizações
This regular expression breaks on safari but works in Google Chrome, how do I make it work in both

I have a regex:

var regex = /(layout)(^|\s*)((?<!=)=(?!=))(^|\s*)/;

This works on Google Chrome but not on Safari and neither on Internet Explorer. On Safari, the error is:

"Invalid regular expression: invalid group specifier name"

How can I fix this, please?

UPDATE I have an xml input on which I run some checks before giving it to the xml parser. One of the checks is that I use string parsing to extract the layout name on included file names.

I try to identify whitespaces on the 'layout' attribute and clean it up e.g.

<Container
width="match_parent"
height="wrap_content">

<include
width="20px"
height="30px"
layout  =   "subcontent.xml"
/>
</Container>

would be changed to

<Container
width="match_parent"
height="wrap_content">

<include
width="20px"
height="30px"
layout="subcontent.xml"
/>

</Container>

I do this using a String.replace, then I extract the included file name and load it from storage and queue it for parsing also.

So think:

let check = 'layout=';

//change layout[space....]=[space.....] to layout=
let regex = /(layout)(^|\s*)((?<!=)=(?!=))(^|\s*)/;
xml = xml.replace(regex, check);

I hope its clearer now.

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

0

Use

let check = 'layout=';
let xml = "change layout    =   ";
let regex = /layout\s*=(?!=)\s*/g;
xml = xml.replace(regex, check);
console.log(xml)

See regex proof.

EXPLANATION

"layout" - matches the characters layout literally (case sensitive)
"\s*" matches any whitespace character between zero and unlimited times, as many times as possible, giving back as needed (greedy)
"=" - matches the character = with index 6110 (3D16 or 758) literally
 - Negative Lookahead "(?!=)":
   Assert that the Regex below does not match
    "=" - matches the character = with index 6110 (3D16 or 758) literally
"\s*" - matches any whitespace character between zero and unlimited times, as many times as possible, giving back as needed (greedy)
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