메모장++ 줄 뒤집기/재주문

메모장++ 줄 뒤집기/재주문

단순화된 다음 코드 블록의 인스턴스가 많이 있습니다.

$image = '';
$name = '';
$link = '';
$role_suffix = '';
$role_name = '';
$notes = '';

이러한 모든 변수에는 서로 다른 데이터가 포함되어 있습니다. 내 파일을 배열로 변환해야 합니다. 이는 간단한 검색 및 바꾸기로 수행할 수 있지만 $link먼저 $image. 따라서:

$link = '';
$name = '';
$image = '';
$role_suffix = '';
$role_name = '';
$notes = '';

수동으로 모두 변경하는 것을 저장하는 정규식 솔루션이 있어야 합니까? 다른 질문에서 찾은 답변을 함께 해킹해 보았지만 정규식은 전혀 의미가 없습니다! 나는 이것을 가지고 놀았고 (<div>.*?</div>)(\s+)(<span>.*?</span>)다음으로 바꾸었지만 \3\2\1올바른 구문이 확실하지 않습니다.

답변1

  • Ctrl+H
  • 무엇을 찾다:(\$image\h*=\h*.+?;)([\s\S]+?)(\$link\h*=\h*.+?;)
  • 다음으로 교체:$3$2$1
  • 둘러보기 확인
  • 정규식 확인
  • 선택 취소. matches newline
  • Replace all

설명:

(               # 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

화면 캡처:

여기에 이미지 설명을 입력하세요

관련 정보