0

#i am using regex to split this but i am getting wrong results.

import re

queries ="""
INSERT ignore into persons VALUES (15,'Tom D.', 'Erilchsen', 
'Skagen 21', 'Erlangen');
select * from persons;
"""

regex = "[;!]+?"
y = re.split(regex ,queries)
print(y)
print(len(y))
print(y[0])

output:

["\nINSERT ignore into persons VALUES (15,'Tom D.', 'Erilchsen', \n'Skagen 21', 'Erlangen')", '\nselect * from persons', '\n']
3
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

0

You don't actually need a regex for this:

queries ="""
INSERT ignore into persons VALUES (15,'Tom D.', 'Erilchsen', 
'Skagen 21', 'Erlangen');
select * from persons;
"""

y = list(filter(None, queries.replace("\n", "").split(";")))
print(y)
print(len(y))
print(y[0])
pigrammer
  • 2,603
  • 1
  • 11
  • 24