Question: So I'm working on a DATE validation. The date format that I'm going to use is `mm/dd/yyyy`. May I ask if it is possible if a `/` will be **automatically** inserted while typing? And, I'm also thinking if how can I validate if the value is a real date or not.

The code below allows the textbox to accept `numbers` and a `/`. It is under the `Class File`.

```
If KeyAscii >= 47 And KeyAscii <= 57 Then
      Debug.Print tb.Name, "date"
   Else
      MsgBox "The value should be in a DATE format: mm/dd/yyyy", vbOKOnly + vbCritical, "Error"
      Debug.Print tb.Name, "other"
      KeyAscii = 0
End If

```

Should I stick in modifying the `Class` file or is there a way for me to do it on the `Userform` file?

Answer: 
Using `re.sub` we can try first removing the unwanted repetitive text. Then, do a second replacement to replace remaining newlines with single spaces:

```py
inp = """1
00:00:05.210 --> 00:00:07.710
In this lecture, we're
going to talk about

2
00:00:07.710 --> 00:00:10.815
pattern matching in strings
using regular expressions.

3
00:00:10.815 --> 00:00:13.139
Regular expressions or regexes

4
00:00:13.139 --> 00:00:15.825
are written in a condensed
formatting language."""

output = re.sub(r'(?:^|\r?\n)\d+\r?\n\d{2}:\d{2}:\d{2}\.\d{3} --> \d{2}:\d{2}:\d{2}\.\d{3}\r?\n', '', inp)
output = re.sub(r'\r?\n', ' ', output)
sentences = re.findall(r'(.*?\.)\s*', output)
print(sentences)

```

This prints:

```
["In this lecture, we're going to talk about pattern matching in strings using regular expressions.",
 'Regular expressions or regexes are written in a condensed formatting language.']

```
You can also match the structure of the data in the file to make sure that it is present.

```
^\d+\r?\n\d{2}:\d{2}:\d{2}\.\d{3} -->.*\r?\n((?:(?!\d+\r?\n\d\d:).*(?:\r?\n|$))*)

```

**Expanation**

* `^` Start of string
* `\d+\r?\n\d{2}:\d{2}:\d{2}\.\d{3} -->.*` Match 1+ digits, a newline and the time like pattern
* `\r?\n` match a newline
* `(` Capture **group 1**
	+ `(?:` Non capture group
		- `(?!\d+\r?\n\d\d:).*(?:\r?\n|$)` Match the whole line if it does not start with a time like pattern
	+ `)*` Close the group and repeat 0+ times to match all the lines
* `)` Close group 1

See an online [regex demo](https://regex101.com/r/HWsX6f/1) | [Python demo](https://ideone.com/decFc9)

Match all the text after time pattern in a capture group that will be returned by [re.findall](https://docs.python.org/3/library/re.html#re.findall) in a list.

Then join all the parts an empty string, replace the newlines by a space and split on 1 or more whitespace chars after a dot.

**Example code**

```
regex = r"^\d+\r?\n\d{2}:\d{2}:\d{2}\.\d{3} -->.*\r?\n((?:(?!\d+\r?\n\d\d:).*(?:\r?\n|$))*)"
content = [i for i in re.split(r"(?<=\.)\s+", re.sub(r"[\r\n]+", " ", "".join(re.findall(regex, text, re.M)))) if i]
print(content)

```

**Output**

```
["In this lecture, we're going to talk about pattern matching in strings using regular expressions.", 'Regular expressions or regexes are written in a condensed formatting language.']

```