Skip to main content
Participant
June 29, 2018
Answered

GREP to keep telephone number from breaking

  • June 29, 2018
  • 1 reply
  • 961 views

I'm a recent GREP crusader and after a few weeks or working with it, some of it is sinking in and starting to make sense. I'm creating a master template with paragraph styles and one of the many things I'm using GREP for is ensuring telephone numbers don't break over lines. I thought I had solved it but

(\d+ \d+)+

isn't cutting the mustard.

My telephone numbers will never be separated by punctuation but would need to account for several european/regional formats. Example formats could be; 0 00 00 000..., 0000 000 000, 00000 000000, etc. The telephone numbers could appear in the middle of paragraphs too.

I've tried quite a few variations now and I'm not sure where to go - any help would be appreciated!

EDIT: Well I feel stupid now but I thought this might help someone else. I fixed it with;

(\d+? \d+?)+

This topic has been closed for replies.
Correct answer FRIdNGE

\d[\d\h]+\d

1 reply

FRIdNGE
FRIdNGECorrect answer
June 29, 2018

\d[\d\h]+\d

JE_D+PAuthor
Participant
June 29, 2018

Thanks. I'm curious as to what your expression is better than my edit?

winterm
Legend
June 29, 2018

Didn't you notice that your regex doesn’t work (expectedly) on your own - second - sample?

Michel's one is much more flexible and universal, and still safe.