Small developer Small developer - 1 year ago 44
PHP Question

Regex isn't working properly with PHP or not getting how to implement this

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


What I'm trying to do is starting of string:

1=> Check the first character is

2=> and the Second thing is String cannot be like this
it must be like
and sequence.

3=> Ending character must be
and won't be

However, I can match the first character like so
But when I'm trying this same way with ending character it is not working and I'm not getting how to do the step

Save my day guys. Thanks

Failed Regex:

Answer Source

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 .s
+ 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: (Probably with a clearer description than I provided)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download