본문 바로가기

Remove3

[#golang] 스페이스(white space) 여러 개를 1개로 바꾸기 텍스트를 다듬다 보면 스페이스, 띄워쓰기(white space) 여러개를 1개로 바꾸고 싶을 때가 있다. 이 경우, 정규식으로 간단하게 해결할 수 있다. package main import ( "regexp" ) // RemoveMultiSpaces : 스페이스 삭제 func RemoveMultiSpaces(str string) string { reLeadcloseWhtsp := regexp.MustCompile(`^[\s\p{Zs}]+|[\s\p{Zs}]+$`) reInsideWhtsp := regexp.MustCompile(`[\s\p{Zs}]{2,}`) result := reLeadcloseWhtsp.ReplaceAllString(str, "") result = reInsideWhtsp.Replac.. 2020. 3. 30.
[#golang] html 태그 제거(strip tags) golang으로 html 페이지를 크롤링하다보면 가끔 태그를 제거하고 텍스트만 받고 싶은 경우가 있다. 이럴때는 package main import ( "fmt" "github.com/grokify/html-strip-tags-go" ) func main() { text := "Hello World!this is in div element." stripped := strip.StripTags(text) fmt.Println(text) fmt.Println(stripped) } 를 사용하면 간단하게 해결할 수 있다. 2020. 3. 30.
[#python] 리스트 자유자재로 다루기 python 리스트(list) 잘 쓰면 개발 생산성이 급격히 올라갈 수 있다. 30초만 투자해서 간단하지만 익혀두면 정말 유용한 리스트 관련 메소드를 알아보자 1. 리스트 요소 추가 (list item insert) # 제일 뒤에 요소 추가 list.append(item) # 또는 list.insert(len(list) - 1, item) # 제일 앞에 요소 추가 list.insert(0, item) # 원하는 위치에 요소 추가 list.inset(n, item) 2. 리스트 요소 삭제 (list item delete/remove) # 제일 뒤에 요소 삭제 del list[len(list) - 1] # 제일 앞에 요소 삭제 list.pop(0) # 또는 del list[0] # 원하는 위치 요소 삭제 d.. 2020. 3. 24.