I need regular expression to select whitespaces excluding whitespaces after prepositions (or short words, 1-3 char).
Example: Namesti I. P. Pavlova
only selected whitespace will be after word "Namesti".
CodePudding user response:
You can use a lookback.
I have only put a point in the look back. You could add comma, colon, semi-colon etc. if needed.
((?<![.])\s)
see https://regex101.com/r/7MLjkh/1
CodePudding user response:
If we want the space to follow a minimum of 4 letters we can use
((?<=[a-zA-Z]{4})\s)
See https://regex101.com/r/Tlp2xS/1
If numbers are also accepted
((?<=[a-zA-Z0-9]{4})\s)
Or the shorter pattern
((?<=\w{4})\s)
Test to see what suits your needs because you have only given one sample string so there may be edge cases you haven't mentioned.