이렇게 나온 값을 한줄씩 나누어지게 하고 싶은데 어떻게 해?
- User
이렇게 나온 값을 한줄씩 나누어지게 하고 싶은데 어떻게 해?
- Assistant
네! 정규식으로 매칭한 결과(즉,
regex_search의 결과)를 한 줄씩 나누고 싶다면, 파이썬을 예시로 들면 아래처럼 할 수 있습니다.예시 코드:
pythonimport re text = """---- header1 data1 data2 Total ---- header2 data3 data4 Total """ pattern = r"^----\s+\S+.*$(?:\n(?!Total).*)*(?=\nTotal)" matches = re.findall(pattern, text, re.MULTILINE) for match in matches: lines = match.splitlines() for line in lines: print(line) print('--- 구분선 ---')설명
re.findall()로 원하는 블록을 모두 추출합니다.- 각 블록(
match)을splitlines()로 한 줄씩 나눕니다.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.