File size: 858 Bytes
19fc84f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import re


def extract_tag_content(input_string):
    # Use regular expression to find all content between <s> and </s> tags
    pattern = re.compile(r"<s>(.*?)</s>")
    matches = pattern.findall(input_string)
    return matches


def extract_array_result(input_string):
    # Use regular expression to find array result betweenn []
    # Assume input only have 1 array, or just want to get first array
    pattern = re.compile(
        r"\[(.*?)\]", re.DOTALL
    )  # Use DOTALL to handle multiline content
    matches = pattern.findall(input_string)
    if len(matches) > 0:
        return matches[0]
    return "[]"


def extract_string_array(input_string):
    items = input_string.strip("[").strip("]").strip('"').strip().split(";")
    # remove empty string in list and trim \n
    items = [i.replace("\n", "") for i in items if i]
    return items