Regex2 정규식 regex - 파일이름 일괄 바꾸기 정규표현식 - 콘솔에서 파일이름 바꾸기 From: model-114260.data-00000-of-00001 model-114260.index model-114260.meta To: model.data-00000-of-00001 model.index model.meta $ ls |grep model | sed "s/model-\w*\.\(\S*\b\)/mv '&' 'model.\1'/" |sh \1 == (\S*\b) From 파일의 .뒷부분 $ mv 'model-114260.data-00000-of-00001' 'model.data-00000-of-00001' $ mv 'model-114260.index' 'model.index' $ mv 'model-114260.meta' 'model.meta' Sy.. 2020. 6. 21. 파이썬 정규식(regular expression:regex) 사용 - 일부만 추출 파이썬에서 정규식 사용 정규식으로 찾고 일부만 추출하기 >>> import re >>> _str=" 65 0 0 -50 243 323 Tm\n asdfasdf" # 정규식에서 `()`로 싸여진 곳이 `group` >>> matches = re.finditer(r"^\d+ \d+ \d+ \-\d+ (\d+) \d+ Tm$",b,re.MULTILINE) >>> for match in matches: ... print(match.group()) ... group_num = len(match.groups()) ... print(match.group(group_num)) ... 65 0 0 -50 243 323 Tm 243 2020. 6. 15. 이전 1 다음