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

266
Visualizações
Regex - extract string between double quotes where line starts with a keyword

Given the following lines:

classes!("text-xl", "text-blue-500")
String::from("test")
classes!("text-sm")

I wish to extract text-xl, text-blue-500 and text-sm and potentially any other strings within classes!

What I have so far is:

  • (?<=classes!).* - this gives me everything after classes! but not the exact values
  • (?!^")".*?" - this gives me the values I want with but with the quotes
  • I use the global and multi line flags
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you are using Javascript, and the positive lookbehind is supported (you don't need the multiline flag, only the global flag)

(?<=classes!\((?:"[^"]*",\s*)*")[^"]*(?=")
  • (?<= Positive lookbehind to assert to the left
    • classes!\( Match classes!(
    • (?:"[^"]*",\s*)* Match optional repetitions of "...",
    • " Match a double quote
  • ) Close lookbehind
  • [^"]* Match optional chars other than "
  • (?=") Assert " to the right

Regex demo

const regex = /(?<=classes!\((?:"[^"]*",\s*)*")[^"]*(?=")/g;
const str = `classes!("text-xl", "text-blue-500")
String::from("test")
classes!("text-sm")
`;
console.log(str.match(regex))

about 4 years ago · Juan Pablo Isaza Relatório

0

You could try a non fixed-width lookbehind like so:

(?<=^classes!\("(?:[^"]*"[^"()]*")*)[^"]*

See an online demo


  • (?<= - Open a positive lookbehind;
    • ^classes!\(" - Start-line anchor and match literally 'classes!("';
    • (?:[^"]*"[^()"]*")* - A nested non-capture group to match (0+ times) any char other than quotes (and paranthesis), a quote and that same sequence repeated.
    • ) - Close lookbehind;
  • [^"]* - Match 0+ (Greedy) characters other than quotes.
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