Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find, and standardize the spelling of chapter and page references (Adobe InDesign)?

I want to find digits followed by "f", "ff", "f." or "ff." to standardize the spelling following given conventions/rules.

I already tried some regular expressions, but unfortunately I did not find an universal expression grabbing all of the cases above (f, ff, f., ff.).

In spoken words it seems easy:

  • find digits
  • followed by an optional whitespace
  • then followed by f, ff, f. or ff.
  • only whitespaces or NOT word boundaries are allowed before and after the expression

The beginning of the regex is quite easy, but I can’t figure out how to handle the different "f"-cases and the NOT boundaries following.


My best guess yet is:

(?<=\b)(\d+(\h|\b)?f{1,2})\.?

but then still the stings followed by a word character are found.


When I extend the regex to:

(?<=\b)(\d+(\h|\b)?f{1,2})\.?(\W)

the numbered of "false funds" are decreasing, but still it is not the solution


I prepared lines for testing. The lines containing a plus "+" should be found, at the same time the ones with a minus "-" should not be found.

00f aaa +
00f. aaa +
00ff aaa +
00ff. aaa +
00 f aaa + 
00 f. aaa +
00 ff aaa +
00 ff. aaa +
+ aaa 00f aaa +
+ aaa 00f. aaa +
+ aaa 00ff aaa +
+ aaa 00ff. aaa +
+ aaa 00 f aaa + 
+ aaa 00 f. aaa +
+ aaa 00 ff aaa +
+ aaa 00 ff. aaa +
+ aaa 00f
+ aaa 00f.
+ aaa 00ff
+ aaa 00ff.
+ aaa 00 f 
+ aaa 00 f.
+ aaa 00 ff
+ aaa 00 ff.

00 faaa -
00 f.aaa -
00 ffaaa -
00 ff.aaa -
00af aaa - 
00af. aaa -
00aff aaa -
00aff. aaa -
- aaa 00 faaa -
- aaa 00 f.aaa -
- aaa 00 ffaaa -
- aaa 00 ff.aaa -
- aaa 00af aaa - 
- aaa 00af. aaa -
- aaa 00aff aaa -
- aaa 00aff. aaa -
- aaa00f
- aaa00f.
- aaa00ff
- aaa00ff.
- aaa 00af 
- aaa 00af.
- aaa 00aff
- aaa 00aff.

00faaa -
00f.aaa -
00ffaaa -
00ff.aaa -
00af aaa - 
00af. aaa -
00aff aaa -
00aff. aaa -
- aaa00 faaa -
- aaa00 f.aaa -
- aaa00 ffaaa -
- aaa00 ff.aaa -
- aaa00af aaa - 
- aaa00af. aaa -
- aaa00aff aaa -
- aaa00aff. aaa -
- aaa00af 
- aaa00af.
- aaa00aff
- aaa00aff.

Further, the aim is to group the digits anf "f"-cases in a manner, so that they can be uses in a replacement-expression to standardize the spelling to one of those cases:

  • 123 ff. (with whitespace, with dot)
  • 123 ff (with whitespace, without dot)
  • 123ff. (without whitespace, with dot)
  • 123ff (without whitespace, without dot)
like image 809
typopaul Avatar asked Aug 20 '19 21:08

typopaul


People also ask

How do you check spelling in InDesign?

Choose Edit > Preferences > Autocorrect (Windows) or InDesign > Preferences > Autocorrect (Mac OS). Choose Enable Autocorrect. (You can also choose Edit > Spelling > Autocorrect to turn this feature on or off quickly.)

How do you do chapter numbering in InDesign?

Place the insertion point where you want the chapter number to appear, and then choose Type > Text Variables > Insert Text Variable > Chapter Number.

How do you do referencing in InDesign?

Choose Type > Hyperlinks & Cross-References > Insert Cross-Reference. Choose Window > Type & Tables > Cross-References, and then choose Insert Cross-Reference from the panel menu. Click the Create New Cross-Reference button in the panel.

How do you find and replace words in InDesign?

Choose Edit > Find/Change, and then click the Text tab. Specify the range of your search from the Search menu, and click icons to include locked layers, parent pages, footnotes, and other items in the search. In the Find What box, describe what you want to search for: Type or paste the text you want to find.


2 Answers

I suggest

\b(\d+)(\s?)(f{1,2})(?:(\.)\B|\b(?!\.))

See the regex demo

Details

  • \b - word boundary
  • (\d+) - Group 1: 1+ digits
  • (\s?) - Group 2: an optional whitespace
  • (f{1,2}) - Group 3: 1 or 2 fs
  • (?:(\.)\B|\b(?!\.)) - either of the two:
    • (\.)\B - a . captured in Group 4 if not followed with a word char
    • | - or
    • \b(?!\.) - a word boundary not followed with a dot.

Then, replacing is easy with:

  • 123 ff.: $1 $3.
  • 123 ff : $1 $3
  • 123ff. : $1$3.
  • 123ff : $1$3

If the whitespace and dot are not necessary in replacement patterns, remove the groupings and adjust the IDs in the replacement backreferences.

like image 116
Wiktor Stribiżew Avatar answered Sep 25 '22 18:09

Wiktor Stribiżew


What about something like this?

\b\d+\s?(?:ff|f)+\.?(?=\s)

enter image description here

Regex Demo

\b          start with word boundary
\d+         match all digits
\s?         match optional whitespace
(?:ff|f)+   non-capturing group, match either ff or f
\.?         match optional dot (basically checking for ff. or ff or f. or f)
(?=\s)      match if followed by whitespace, without making the whitespace part of the match

With groups, same expression looks like:

\b(\d+)\s?((?:ff|f)+\.?)(?=\s)

enter image description here

Regex Demo

Replacement can be achieved via different combinations of the $1 and $2 groups.

like image 38
vs97 Avatar answered Sep 24 '22 18:09

vs97