Regular Expressions Word Boundary Make text shorter but don't break last word


Example

To make long text at most N characters long but leave last word intact, use .{0,N}\b pattern:

^(.{0,N})\b.*