Skip to content

Instantly share code, notes, and snippets.

@MangKyu
Last active January 6, 2023 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MangKyu/8205f167f811249388ce42ea402afefd to your computer and use it in GitHub Desktop.
Save MangKyu/8205f167f811249388ce42ea402afefd to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"regexp"
"strings"
)
var pattern = `^\[[0-9a-fA-F]{32}\][[:space:]][0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]][0-9]{2}:[0-9]{2}:[0-9]{2}[[:space:]]\[`
var content = `[42744e73aebe5366cf627e8cf71c3da6] 2022-12-29 17:31:43 [DEBUG](GetProductService :118) 안녕하세요 이것은 테스트용 문장입니다.
multiline이 어디까지 적용되나 확인중입니다.
개행을 하겠습니다.
[bacd4e73aebe5366cf627e8cf71c3da6] 2022-12-29 17:31:43 [DEBUG](GetProductService :118) 안녕하세요 이것은 테스트용 문장입니다.
multiline이 어디까지 적용되나 확인중입니다.`
func main() {
regex, err := regexp.Compile(pattern)
if err != nil {
fmt.Println("Failed to compile pattern: ", err)
return
}
lines := strings.Split(content, "\n")
fmt.Printf("newLine\tline\n")
for _, line := range lines {
matches := regex.MatchString(line)
fmt.Printf("%v\t%v\n", matches, line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment