Search code examples
regexgoogle-sheetsgoogle-sheets-formula

Regex between two specific characters


Text:

John walks to school. He walks past some trees. The leaves on the trees are brown. There are children on bikes. This is a normal morni...

John reaches school. He is greeted by his teacher.

The above is an example of the type of text Im looking to edit. I've been trying to use regex to match ... and the preceeding . . (example, match everything between ...and the preceeding full stop.

I need to target

This is a normal morni

I can match the ... but its the matching backwards to the full stop I cant get.

When I put that into Google Sheets

=REGEXREPLACE(A2, "\.(?!.*\. ).*?\.{3}",C2)

it says its not a regular expression, but I can see that it works in regex101.com


Solution

  • You can use

    REGEXPEXTRACT(A2, "\.([^.]*)\.{3}")
    

    See the regex demo.

    It should work IF there are no other dots in the part between the dot and three dots.

    Details:

    • \. - a dot
    • ([^.]*) - Group 1: any zero or more chars other than .
    • \.{3} - three . chars.