This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
public:nnels:etext:regex [2017/11/02 18:46] farrah.little |
public:nnels:etext:regex [2018/07/12 17:07] leah.brochu |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Regular Expressions ====== | ====== Regular Expressions ====== | ||
Regular expressions (aka regex) is useful for replacing patterns of text, such as headers/ | Regular expressions (aka regex) is useful for replacing patterns of text, such as headers/ | ||
+ | |||
+ | With regex, you can define patterns of text in a number of different ways, but the most commonly used ones for our purposes are **Ranges** and **Groups**. For more information about others, you can take a look at [[https:// | ||
+ | * Ranges | ||
+ | * Square brackets are always used in pairs and are used to identify //specific characters// | ||
+ | * [A-Z] will find any upper case letter; | ||
+ | * [a-z] will find any lower case letter; | ||
+ | * [A-z] will find any letter (upper or lower case); | ||
+ | * [0-9] will find any number | ||
+ | * [abc] will find any of the letters a, b, or c. | ||
+ | * [F] will find upper case “F” | ||
+ | * [Fred] will find " | ||
+ | * Groups | ||
+ | * Round brackets are used in pairs to enclose //groups//. For example: | ||
+ | * '' | ||
+ | * They must be used in pairs and are addressed by number in the replacement. In the replace field, \1 represents the first group, \2 represents the second group, and so on. For example: | ||
+ | * If you wanted to remove the hyphen from " | ||
+ | * Another example: '' | ||
====Tips==== | ====Tips==== | ||
Line 6: | Line 23: | ||
[[https:// | [[https:// | ||
- | * Word has a lot of options to find letters (^$) and numbers (^#) but these only work with the wildcard option //off// (which it is by default). Only turn the wildcard option on if you're using regex options. Read the info page carefully on when things apply with the wildcard option on/off. | + | * Word has a lot of options to find letters (^$) and numbers (^#) when using the non-regex [[public: |
* A lot of the codes for special characters (e.g. page break) are under the " | * A lot of the codes for special characters (e.g. page break) are under the " | ||
Line 23: | Line 40: | ||
---- | ---- | ||
+ | <WRAP center round box 80%> | ||
**PROBLEM**: | **PROBLEM**: | ||
- | **SOLUTION**: | + | **SOLUTION**: |
In Word, this will only work with wildcards turned on. | In Word, this will only work with wildcards turned on. | ||
Line 33: | Line 51: | ||
Replace with: '' | Replace with: '' | ||
- | This looks for the pattern: any-letter space paragraph-break any-letter | + | This looks for the pattern: |
The parentheses are used to group what it finds, so \1 refers to the first " | The parentheses are used to group what it finds, so \1 refers to the first " | ||
In this way, you are putting back exactly what it found minus the paragraph break. | In this way, you are putting back exactly what it found minus the paragraph break. | ||
+ | </ | ||
---- | ---- | ||
+ | <WRAP center round box 80%> | ||
**PROBLEM**: | **PROBLEM**: | ||
Line 52: | Line 72: | ||
You will likely have to do it again for lines that end with a comma, and possibly en and em dash. Look through your document for patterns of anything else it might have missed. | You will likely have to do it again for lines that end with a comma, and possibly en and em dash. Look through your document for patterns of anything else it might have missed. | ||
+ | </ | ||
---- | ---- | ||
- | **PROBLEM**: There are extra paragraph breaks. We want to keep the real paragraph breaks and remove the fake extra paragraph breaks. | + | <WRAP center round box 80%> |
+ | **PROBLEM:** OCR converted some " | ||
- | **SOLUTION**: Use MS Word's find and replace to remove the extra paragraph breaks using special Word symbols. | + | **SOLUTION:** Replace " |
- | Find: '' | + | - |
- | + | - Find: '' | |
- | Replace | + | - Replace: |
+ | - | ||
+ | - Find: '' | ||
+ | | ||
+ | </ | ||
---- | ---- | ||
- | **PROBLEM**: | + | <WRAP center round box 80%> |
- | **SOLUTION**: Find and remove all line breaks and replace | + | **PROBLEM:** OCR did not recognize spaces around quotation marks. |
+ | * Example A: As one of Montgomery' | ||
+ | * Example B: The "nasty little '' | ||
+ | This problem has an added complexity; the pattern has two different solutions: | ||
+ | * Example A will need to say: ... later put '' | ||
+ | * Example B will need to say: The "nasty little troublemaker''," | ||
- | Find: '' | + | **SOLUTIONS:** |
+ | Example A:\\ | ||
- | Replace | + | Find: '' |
+ | Replace: '' | ||
- | In LibreOffice, | + | Example B: |
- | **PROBLEM**: Running headers. Example, where the first three numbers and the three numbers after the filename is the page number: | + | Find: '' |
- | '' | + | Replace: '' |
- | **SOLUTION**: Without using wildcards: | + | Notes: |
+ | | ||
+ | * You will also need to re-do this, searching for periods instead of commas. | ||
- | Find: '' | + | </WRAP> |
- | Replace with: nothing. If you're doing a paginated title, replace with page breaks. | + | ---- |
- | You will need to remove one of the ^# at the beginning and after the .indd to remove it for 2 digit page numbers, and one last time for single digit page numbers. The following screenshot is an example with a 1-digit page number (see below), followed by the command used to isolate all such instances. | ||
- | <WRAP center round box 60%> | + | <WRAP center round box 80%> |
+ | **PROBLEM**: | ||
- | {{:nnels:documentation:content:production:screen_shot_2015-08-06_at_6.10.55_pm.png? | + | **SOLUTION**: See: [[public:nnels:etext:find-and-replace|Find & Replace]] |
+ | </ | ||
- | Find: ^# | + | ---- |
+ | |||
+ | <WRAP center round box 80%> | ||
+ | **PROBLEM**: There are newlines/line breaks (↵) instead of paragraph marks (¶). | ||
+ | |||
+ | **SOLUTION**: See: [[public: | ||
</ | </ | ||
- | You will also need to do it with the leading ^#^p to catch the footer text that do not have any page numbers | + | ---- |
+ | |||
+ | <WRAP center round box 80%> | ||
+ | **PROBLEM**: | ||
+ | '' | ||
+ | |||
+ | **SOLUTION**: | ||
+ | </ | ||
In LibreOffice: | In LibreOffice: |