줄 끝 - 파이프 추가 |

줄 끝 - 파이프 추가 |

각 줄 끝에 정규식을 사용하여 파이프를 배치하는 방법을 설명할 수 있는 사람이 있습니까?

메모장에서 찾기 및 바꾸기 사용 ++

배치하려고 해요content |

건배!

답변1

각 줄의 끝에 파이프를 추가하려면 다음 '찾기' 정규식을 사용하세요.

$

(달러 기호는 정규식의 줄 끝과 일치합니다)

그리고 이 '교체'는 다음과 같습니다.

|

정규식 찾기를 활성화했는지 확인하세요.

답변2

무엇을 찾다:(.*)

다음으로 교체:$1|

이는 다음을 사용합니다.그룹화, $1기본적으로 괄호 안에 있는 내용을 삽입한 다음 파이프를 끝에 추가하라는 의미입니다. .이 상황에 이상적인 줄 바꿈과 같은 특정 공백을 제외한 모든 문자를 캡처합니다 . 이 *방법을 사용하면 0개 이상의 문자를 캡처할 수 있습니다..

이는 확장 가능하므로 특정 라인(예: test가 포함된 라인)만 캡처하려는 경우:

무엇을 찾다:(.*test.*)

다음으로 교체:$1|

따라서 이를 입력하고 "모두 바꾸기"를 누르면 정규식과 일치하는 각 줄 끝에 파이프가 표시됩니다.

답변3

답변이 변경되었습니다.
나는 이것을 사용할 것이다. 나는 단일 또는 다중 라인 모드에서 작업합니다.
어떤 메모장을 사용할 수 있는지 잘 모르겠습니다(예: 검색/바꾸기, 찾기/바꾸기 등).
다음을 찾아 (?=\r\n|\n|\r|$)
다음을 삽입(바꾸기)하세요. |

$ Metachar가 실제로 무엇인지에 대한 복잡한 주제에 대한 몇 가지 참고 사항입니다.
생각만큼 쉽지는 않으며 문서에는 부족한 부분이 많습니다.

어쨌든 여기에 내 의견이 있습니다 -

 # Regular Expression Docs:
 # Metacharacter  $ 
 # Match the end of the line (or before newline at the end)
 # ** This really is misworded, it really means:
 #
 #    In single line mode,
 #      In two separate matches (in global context) 
 #         Match before and after a newline at the end of a string if there is a newline,
 #      OR, Match the end of the string only.
 #
 #    In multi-line mode,
 #         Match before OR after a newline at the end of a line or string,
 #         but not both.
 #
 # ---------------------------------------------
 # The above explanation is conditional upon the qualifying 
 # subexpressions surrounding the $ metachar
 # ---------------------------------------------

 # /$/g  Single line mode:
 # Matches before newline (if there is one) AND end of string (always this)

 print "=== /\$/g ===============\n";
    $str = "0  ";          $str =~ s/$/|/g;  print "'$str'\n---\n";
    $str = "1  \n";        $str =~ s/$/|/g;  print "'$str'\n---\n";
    $str = "2  \n\n";      $str =~ s/$/|/g;  print "'$str'\n---\n";
    $str = "3  \n\n\n";    $str =~ s/$/|/g;  print "'$str'\n---\n";
    $str = "4  \n\n\n\n";  $str =~ s/$/|/g;  print "'$str'\n\n";

 # /$/mg   Multi-line mode:
 # Matches before each newline (if there is one) OR end of string (not both)

 print "===  /\$/mg ===============\n";
    $str = "0  ";          $str =~ s/$/|/mg;  print "'$str'\n---\n";
    $str = "1  \n";        $str =~ s/$/|/mg;  print "'$str'\n---\n";
    $str = "2  \n\n";      $str =~ s/$/|/mg;  print "'$str'\n---\n";
    $str = "3  \n\n\n";    $str =~ s/$/|/mg;  print "'$str'\n---\n";
    $str = "4  \n\n\n\n";  $str =~ s/$/|/mg;  print "'$str'\n\n";

 # /(?=\r\n|\n|\r|$)/g   Single line mode:
 # Parsing the expression for //m Multi-line mode,
 # Equivalent of /$/m  can now be run in Single line mode:
 # This is What /$/m  probably really is.
 # Matches before each newline (if there is one) OR end of string (not both)

 print "=== /(?=\\r\\n|\\n|\\r|\$)/g ==============\n";
    $str = "0  ";          $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n---\n";
    $str = "1  \n";        $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n---\n";
    $str = "2  \n\n";      $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n---\n";
    $str = "3  \n\n\n";    $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n---\n";
    $str = "4  \n\n\n\n";  $str =~ s/(?=\r\n|\n|\r|$)/|/g;  print "'$str'\n\n";

 # /(?=\r\n|\n|\r|$)/mg   Multi-line mode:
 # Exact same output.

 print "=== /(?=\\r\\n|\\n|\\r|\$)/mg ==============\n";
    $str = "0  ";          $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n---\n";
    $str = "1  \n";        $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n---\n";
    $str = "2  \n\n";      $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n---\n";
    $str = "3  \n\n\n";    $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n---\n";
    $str = "4  \n\n\n\n";  $str =~ s/(?=\r\n|\n|\r|$)/|/mg;  print "'$str'\n\n";

출력 >>

 === /$/g ===============
 '0  |'
 ---
 '1  |
 |'
 ---
 '2
 |
 |'
 ---
 '3

 |
 |'
 ---
 '4


 |
 |'

 ===  /$/mg ===============
 '0  |'
 ---
 '1  |
 |'
 ---
 '2  |
 |
 |'
 ---
 '3  |
 |
 |
 |'
 ---
 '4  |
 |
 |
 |
 |'

 === /(?=\r\n|\n|\r|$)/g ==============
 '0  |'
 ---
 '1  |
 |'
 ---
 '2  |
 |
 |'
 ---
 '3  |
 |
 |
 |'
 ---
 '4  |
 |
 |
 |
 |'

 === /(?=\r\n|\n|\r|$)/mg ==============
 '0  |'
 ---
 '1  |
 |'
 ---
 '2  |
 |
 |'
 ---
 '3  |
 |
 |
 |'
 ---
 '4  |
 |
 |
 |
 |'

관련 정보