How to make a regex for this:
[1,31:14:18] SELECT * FROM T.roll1
Here what i tried r'\[[^)] \s' but it is not able to give me a output like:
(1, 31:14:18 ,SELECT * FROM T.roll1)
How to get this output?
You can use something like:
import re
s = "[1,31:14:18] SELECT * FROM T.roll1"
r = [x.strip("[") for x in re.split(",|] ", s)]
print(r)
['1', '31:14:18', 'SELECT * FROM T.roll1']
You will need to do three different regex :
import re
test_str = "[1,31:14:18] SELECT * FROM T.roll1"
first_regex = r"\d+"
second_regex = r",(.*)]"
third_regex = r"] (.*)"
first_matches = re.findall(first_regex, test_str, re.MULTILINE)
second_matches = re.findall(second_regex, test_str, re.MULTILINE)
third_matches = re.findall(third_regex, test_str, re.MULTILINE)
tuple_matches = first_matches[0], second_matches[0], third_matches[0]
print(tuple_matches)
# Output
# ('1', '31:14:18', 'SELECT * FROM T.roll1')
data = re.search(pattern, text, re.IGNORECASE)and after usedata.group(1-3)