Programing

리눅스 정규식 찾기

crosscheck 2020. 11. 1. 17:21
반응형

리눅스 정규식 찾기


find명령 의 정규식을 사용하는 데 문제가 있습니다. 아마도 명령 줄에서 이스케이프하는 것에 대해 이해하지 못하는 것입니다.

왜 같지 않습니까?

find -regex '.*[1234567890]'
find -regex '.*[[:digit:]]'

Bash, Ubuntu


[[:digit:]]에서 사용하는 기본 정규식 구문 에서는 문자 클래스 (예 :)가있는 정규식이 지원되지 않습니다 find. posix-extended사용하려면 다른 정규식 유형을 지정해야 합니다.

모든 정규식 유형과 지원하는 항목을 보여주는 GNU Find의 정규식 문서살펴보십시오 .


-regextype인수를 살펴보아야합니다. 맨 페이지를find 참조하십시오 .

      -regextype type
          Changes the regular expression syntax understood by -regex and -iregex 
          tests which occur later on the command line.  Currently-implemented  
          types  are  emacs (this is the default), posix-awk, posix-basic, 
          posix-egrep and posix-extended. 

emacs유형이 [[:digit:]]구조를 지원하지 않는 것 같습니다 . 나는 그것을 시도했고 posix-extended예상대로 작동했습니다.

find -regextype posix-extended -regex '.*[1234567890]'
find -regextype posix-extended -regex '.*[[:digit:]]'

-regex전체 경로에 따라 달라집니다.

 -regex pattern
              File name matches regular expression pattern.  
              This is a match on the whole path, not a search.

당신은 -regex당신이하는 일에 실제로 사용할 필요가 없습니다 .

find . -iname "*[0-9]"

글쎄, 당신은 이것을 시도 할 수 있습니다 '.*[0-9]'

참고 URL : https://stackoverflow.com/questions/5635651/linux-find-regex

반응형