정규 표현식 질문이요. 문자열 제외하기
글쓴이: goodbbai / 작성시간: 월, 2008/08/18 - 10:19오전
정규 표현식으로 문자열을 제외할 수 있을까요?
하나의 문자만이 아니라 연속된 문자열을 제외하고 싶습니다.
예를 들면,
Refreshes the Project fold that the cursor is in by placing in the
fold all the files that match the filter. The Project is refreshed
using an indent of one space for every foldlevel in the hierarchy.
이런 문장에서 match 를 제외한 모든 글자를 선택하고 싶습니다.
고수님들~ 알려주세요.
Forums:
perl이나 ruby 같은 경우는
perl이나 ruby 같은 경우는
s = "Refreshes the Project fold that the cursor is in by placing in the
fold all the files that match the filter. The Project is refreshed
using an indent of one space for every foldlevel in the hierarchy."
s =~ /match/
print $`, $'
하시면 됩니다.
뭐 다른 것도 비슷하겠지만 $&이부분이 매치된 부분이구요. $` 매치 전 $' 매치 후 문자열입니다.
암튼 문자열도 연속되어서 쓰면 검출 할수 있습니다.
ps) Ruby에서만 Test 했어요
답변
감사합니다. 그런데 제가 이렇게 검출해야할 상황은 스크립트상에서가 아니라 커맨드라인에서 파라미터 넘겨주는 거랑 비슷한 상황이거든요. ㅋ
정규표현식 만으로 해낼 수 있는 방법이 없을까요?
sed의 regular
sed의 regular expression으로 처리될 수 있는 간단한 것이라면
echo "ha kok hihi hA HA" | sed 's/ha//gi'
처럼 sed를 쓰는 것은 어떨까요?
댓글 달기