There is something really I couldn't understand is how can I check my previous match with the next character and set starting and ending character please guys help me.
Here is an Example of my string
This regex should match the description you've given:
^ is the start of the string (or line if
m modifier is used).
(?:\.+?)? is one or more
., but it optional.
A\.+B\.? is looking for an
A any amount of
.s then a
B and an optional
| is an alternative pattern we'll look at
\.\. are 2
+ allows for the whole group to occur once or more
$ is the end of the string (or line, again depends on modifier being used)
Demo: https://regex101.com/r/OUJxxc/3/ (Probably with a clearer description than I provided)