간단한 정규식- "|"로 시작하는 모든 줄을 얻는 방법-[파이프 라인]-[파이프 라인]으로 끝나는 위의 줄로


1

설명

REGEX의 도움으로 이탈리아어 동의어 데이터베이스를 다음 형식으로 변환하려고합니다.

synonym1|synonym2|synonym3
anothersynonym1|anothersynonym2
...........
......

현재이 형식으로 변환되지 않은 동의어 데이터베이스가 있습니다.

a|       - word
|per     -it's synonym
|verso   -another synonym of the word "a" in the second row
abate|    - second word
|priore|superiore
abbacchiare|
|avvilire|deprimere
abbacchiarsi|
|abbattersi|abbiosciarsi|accasciarsi

설명 : 정규식을 사용하여 "|"로 시작하는 모든 줄을 일치시키고 싶습니다. (파이프 라인)으로 이동하고 (파이프 라인)으로 끝나는 줄과 일치하는 단어를 병합하고 "|"로 시작하는 행으로 이동 (끝과 시작) 파이프 라인이있는 파이프 라인 (파이프 라인) 중 하나를 제거하여 원하는 형식을 얻으려면 분명히 병합 될 수 있습니다.

위의 변환되지 않은 데이터베이스에서 변환 된 데이터베이스의 예

a|per|verso
abate|priore|superiore
abbachiare|avvilire|deprimere
abbachiarsi|abbattersi|abbiosciarsi|accasciarsi

텍스트 편집기에서 FIND 및 REPLACE 함수를 사용하여 정확한 정규 표현을 찾도록 도와 줄 수 있습니까?

답변:


0

Windows를 사용하는 경우 메모장 ++ 의 확장 검색 모드를 사용하여 2 단계로 수행 할 수 있습니다.

1 : 바꾸기 |\r\n||- 이것은 최초의 동의어 모두 찾을 수 있습니다

먼저 교체

a|per
|verso
abate|priore|superiore
abbacchiare|avvilire|deprimere
abbacchiarsi|abbattersi|abbiosciarsi|accasciarsi

2 : 바꾸기 \r\n||- 이것은 이후의 동의어 모두 찾을 수 있습니다

두 번째 교체

a|per|verso
abate|priore|superiore
abbacchiare|avvilire|deprimere
abbacchiarsi|abbattersi|abbiosciarsi|accasciarsi

스크린 샷조차도 매우, 매우, 매우 감사합니다, 당신의 솔루션은 정확히 당신이 쓴 방식으로 완벽하게 작동했습니다!
Daniel Foltynek

0
perl -ne 'chomp; print /^(.*)\|\s*$/?"\n$1":$_' filename

a|per|verso
abate|priore|superiore
abbacchiare|avvilire|deprimere
abbacchiarsi|abbattersi|abbiosciarsi|accasciarsi

또는 줄 바꿈을 앞뒤로 까다로워하는 경우 :

perl -ne 'chomp; print /^(.*)\|\s*$/?$.==1?$1:"\n$1":$_;END{print"\n"}' filename
a|per|verso
abate|priore|superiore
abbacchiare|avvilire|deprimere
abbacchiarsi|abbattersi|abbiosciarsi|accasciarsi
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.