# Buggy code
def refresh_text(self):
    self.test_display.SetReadOnly(False)
    self.test_display.Text = self.__test_text
    try:
        parse(self.__value, RegexpState())
    except ValueError as e:
        self.test_display.Text = e.args[0]
        self.test_display.StartStyling(0, 0xFF)
        self.test_display.SetStyling(len(self.test_display.Text), STYLE_ERROR)
        return
    try:
        match = re.search(self.__value, self.__test_text)
        if match:
            for i in range(len(match.groups()) + 1):
                start = match.start(i)
                end = match.end(i)
                self.test_display.StartStyling(start, 0xFF)
                self.test_display.SetStyling(end - start, i + 1)
        else:
            self.test_display.Text = "Regular expression does not match"
            self.test_display.StartStyling(0, 0xFF)
            self.test_display.SetStyling(len(self.test_display.Text), STYLE_ERROR)
    except:
        self.test_display.Text = "Regular expression is not valid"
        self.test_display.StartStyling(0, 0xFF)
        self.test_display.SetStyling(len(self.test_display.GetText()), STYLE_ERROR)
    self.test_display.SetReadOnly(True)


# Traceback (wx._core.wxAssertionError)
Traceback (most recent call last):
File "/Users/bcimini/Documents/GitHub/CellProfiler/CellProfiler/cellprofiler/gui/module_view/_module_view.py", line 1288, in on_button_pressed
new_value = regexp_editor.edit_regexp(
File "/Users/bcimini/Documents/GitHub/CellProfiler/CellProfiler/cellprofiler/gui/regexp_editor.py", line 61, in edit_regexp
frame = RegexpDialog(parent, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
File "/Users/bcimini/Documents/GitHub/CellProfiler/CellProfiler/cellprofiler/gui/regexp_editor.py", line 134, in __init__
sizer.Add(hsizer, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
wx._core.wxAssertionError: C++ assertion "!(flags &amp; wxALIGN_CENTRE_VERTICAL)" failed at /Users/robind/projects/bb2/dist-osx-py38/build/ext/wxWidgets/src/common/sizer.cpp(2077) in DoInsert(): Vertical alignment flags are ignored in vertical sizers

# Fixed code
def refresh_text(self):
    self.test_display.SetReadOnly(False)
    self.test_display.Text = self.__test_text
    try:
        parse(self.__value, RegexpState())
    except ValueError as e:
        self.test_display.Text = e.args[0]
        self.test_display.StartStyling(0)
        self.test_display.SetStyling(len(self.test_display.Text), STYLE_ERROR)
        return
    try:
        match = re.search(self.__value, self.__test_text)
        if match:
            for i in range(len(match.groups()) + 1):
                start = match.start(i)
                end = match.end(i)
                self.test_display.StartStyling(start)
                self.test_display.SetStyling(end - start, i + 1)
        else:
            self.test_display.Text = "Regular expression does not match"
            self.test_display.StartStyling(0)
            self.test_display.SetStyling(len(self.test_display.Text), STYLE_ERROR)
    except:
        self.test_display.Text = "Regular expression is not valid"
        self.test_display.StartStyling(0)
        self.test_display.SetStyling(len(self.test_display.GetText()), STYLE_ERROR)
    self.test_display.SetReadOnly(True)