Tenho muitas instâncias do seguinte bloco de código, simplificado:
$image = '';
$name = '';
$link = '';
$role_suffix = '';
$role_name = '';
$notes = '';
Todas essas variáveis contêm dados diferentes. Preciso transformar meu arquivo em um array, o que posso fazer com uma simples pesquisa e substituição, mas primeiro preciso alternar $link
com $image
. Assim:
$link = '';
$name = '';
$image = '';
$role_suffix = '';
$role_name = '';
$notes = '';
Certamente deve haver uma solução regex para salvar a alteração manual de todos eles? Tentei hackear respostas encontradas em diferentes perguntas, mas o regex não faz sentido para mim! Brinquei com isso (<div>.*?</div>)(\s+)(<span>.*?</span>)
e substituí por, \3\2\1
mas não tenho certeza da sintaxe correta.
Responder1
- Ctrl+H
- Encontre o que:
(\$image\h*=\h*.+?;)([\s\S]+?)(\$link\h*=\h*.+?;)
- Substituir com:
$3$2$1
- confira Envolver
- verifique expressão regular
- DESMARCAR
. matches newline
- Replace all
Explicação:
( # start group 1
\$image # literally
\h* # 0 or more horizontal spaces
= # equal sign
\h* # 0 or more horizontal spaces
.+? # 1 or more any character but newline, not greedy
; # semicolon
) # end group 1
( # start group 2
[\s\S]+? # 1 or more any character, not greedy
) # end group 2
( # start group 3
\$link # literally
\h* # 0 or more horizontal spaces
= # equal sign
\h* # 0 or more horizontal spaces
.+? # 1 or more any character but newline, not greedy
; # semicolon
) # end group 3
Captura de tela: