Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

grep query to find full stop followed by 1 space

Community Beginner ,
Nov 01, 2017 Nov 01, 2017

Hello

Could someone help me with grep queries please?

I want to find all full stops with a single space after it, and then replace it with a full stop and 2 spaces.

I want to find all full stops with 3 spaces after it, and then replace it with a full stop and 2 spaces.

Many thanks

3.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2017 Nov 01, 2017

.... I could help you do that, but I agree with Two spaces after a period: Why you should never, ever do it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2017 Nov 01, 2017

Hi,

… Are you still interested if more than 3 spaces?!… 

(^/)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 01, 2017 Nov 01, 2017

Are you specifically looking for a Grep way to do this? Is easy enough to do in the Find/Change without Grep.

First delete all extra spaces replacing all "(2 spaces)" with "(1 space)" until there's nothing left to replace (that'll clear up all >=3 spaces as well). Then replace all ".(one space)" with ".(2 spaces)".

I frequently run a replace all "(2 spaces)" with "(1 space)" multiple times on documents to clean up any text I've pasted in.

Two spaces after period is incorrect IMHO, though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 03, 2017 Nov 03, 2017

Interestingly when I search for 2 spaces it returns 1 and 3 spaces as well

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2017 Nov 03, 2017

\.\K(\h)(\1{2})?(?!\1)

… will find 1 or 3 spaces following a full stop, but not 2, 4, 5, …

(^/)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 03, 2017 Nov 03, 2017

Oh, as [Jongware] pointed out already, OP just shouldn’t do this...

Let’s help him to do the opposite: clean up multiple spaces between sentences.

Between sentences! That means, we couldn’t use built-in query for replacing multiple spaces to a single space (it may change too much).

On the other hand, we can’t base our query on a full stop only. The sentence usually starts with a uppercase letter and ends with full stop, or question, or exclamation mark. I find this query minimally intrusive:

find what:

[.?!]\s\K\h+(?=\u)

change to:

[leave blank]

It ought to work in most cases. Just if you don’t have some precious tabs between a space followed by . or ? or !, and uppercase letter somewhere in your text... However, if your text is clean enough, there shouldn’t be a space+tab combinations at all.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 04, 2017 Nov 04, 2017

That Grep formula is clever, but as a general rule there is no need ever for there to be double-spaces anywhere in a document. So I still like to run a 'generic' Find/Change of "  " (2 spaces) with " " (1 space) multiple times until I get the 'no changes made' message.

Client-supplied copy is usually a mess, and frequently contains double-spaces between words.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 04, 2017 Nov 04, 2017

Client-supplied copies usually contain much more clutter than just double spaces, that's why there is a good bunch of GREP-based text cleanup scripts floating around, not to mention various collections of Find/Change queries.

It's a totally different story and has no connection to original query of OP.

He's asking just about spaces between sentences, so I intentionally confine solution to it (having regard to the very correct [Jongware]'s post). Again, we're dealing with OP's own texts, likely. Check post 4: he puts double space between sentences himself! Old habits die hard...

I'm just trying to be precise.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 02, 2017 Nov 02, 2017

Well that wasn't the response I was expecting!  I am obviously very old school, I was taught 2 spaces after a full stop and never knew there was a whole discussion regarding it!

Thanks @nicholas@paperchefs.  I had tried to match in text and it wasn't recognising them properly so I will try again.  But now I think I will change everything to one space, many thanks for the input and information everyone!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 05, 2017 Nov 05, 2017

I did have trouble with a few of the suggestions, for example I have indented my page numbers using the indentation function yet this is picked up when I try to find spaces in a variety of ways so I am too nervous to do a change all!!

Thanks for all the help, I still have inconsistencies in my text and deciding whether to worry about it or not

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 05, 2017 Nov 05, 2017

If you could be a bit more specific, ideally - with screenshots, I bet decent solution is possible.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 05, 2017 Nov 05, 2017
LATEST

choc_luver  wrote

... for example I have indented my page numbers using the indentation function yet this is picked up when I try to find spaces in a variety of ways ...

Ouch! That can only mean you did not use "the indentation function" (see the online help: Set tabs and indents in Adobe InDesign​), but multiple spaces! (Because this indent function does not indent your text with spaces.)

Here is a GREP query to locate 2 – and only 2! – spaces after common punctuation. It selects only the space at the end, so you can replace it with nothing.

(?<=[.!?]\x20)\x20(?!\x20)

Don't worry about the "\x20" as it's just a code for a regular space, but if I inserted regular spaces you wouldn't be able to see them.

As emphasized above, this will only and exclusively find punctuation followed by exactly 2 spaces. If you find more spaces than 2, and these should also (always!) be replaced by a single one, then you can use this more general GREP:

(?<=[.!?]\x20)\x20+

which essentially means "punctuation with one space, followed by at least one and possibly more spaces". But use with care: if your author was extremely untrained, he might have used lots-and-lots-and-lots of spaces to 'move the cursor to the next line'. (Unfortunately that is not as uncommon as one may hope, even well into the 2nd decade of the 21st century...)

.. so I am too nervous to do a change all!!

That is a wise attitude. I have a habit of clicking "Change/Find" rather than "Change All" to verify my code actually finds and changes what it's supposed to do. Meanwhile, I keep one eye(*) on the page number (in the bottom left corner), and only if I see that (1) the replacement appears to work reliably and (2) the page number increases very slowly – which would mean there are a lot of changes per page –, then I'd hit "Change All" and get it over with.

(*) The second eye checks the found&changed text. I also must have a third eye because I also keep an eye out for any other possible irregularities in the text. When I spot such ones – say, "10 %", where the space in between ought to be deleted –, I don't interrupt my current find & change but jot down a note to search for that when this run is done.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines