Skip to content

Commit 25c78d8

Browse files
authored
Merge pull request #226 from LibraryCarpentry/abigailsparling-patch-14
Update 10-regular-expressions.md
2 parents 48b80fb + 0d8902b commit 25c78d8

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

episodes/10-regular-expressions.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ exercises: 20
77
::::::::::::::::::::::::::::::::::::::: objectives
88

99
- Understand what regular expressions are and how they can support advanced editing in the MarcEditor
10+
- Bring data and format consistency to fields with varying values by applying edits using a regular expression
11+
- Select a subset of records to edit based on the values in multiple fields using a regular expression
1012

1113
::::::::::::::::::::::::::::::::::::::::::::::::::
1214

@@ -66,17 +68,17 @@ The Find and Replace tool is another useful way to identify and manipulate data
6668

6769
::::::::::::::::::::::::::::::::::::::: checklist
6870

69-
### Add a space between 090 class and subclass
71+
### Add a space between 099 class and subclass
7072

7173
1. Select Edit → Find
72-
2. Enter `=090` in the Find box and click Find All
73-
Review the list of `090` fields, what observations can you make about the call numbers in this field?
74+
2. Enter `=099` in the Find box and click Find All
75+
Review the list of `099` fields, what observations can you make about the call numbers in this field?
7476
Review shows us that not all call numbers begin with letters. We do not want to add a space to these call numbers and need to account for this in our regular expression.
7577
3. In the Find window, click Replace to bring up the Replace Text functions
76-
4. In the Find box enter the regular expression `(=090 \\\\\$a[A-Z]+)(\d.*)`
78+
4. In the Find box enter the regular expression `(=099 \\\\\$a[A-Z]+)(\d.*)`
7779
This regular expression uses two sets of `()` to capture groups and then manipulate them.
7880

79-
- Broken down, the first group `(=090 \\\\\$a[A-Z]+)` will match the literal string `=090 \\$a` (the additional backslashes are used to escape the regex metacharacters `\` and `$` so that they will be read as literals) followed by any single capital letter in the range A to Z (`[A-Z]`) one or more times (`+`). By specifying that the regular expression must locate a capital letter at the start of the call number, the regular expression will not edit the call numbers that begin with a digit.
81+
- Broken down, the first group `(=099 \\\\\$a[A-Z]+)` will match the literal string `=099 \\$a` (the additional backslashes are used to escape the regex metacharacters `\` and `$` so that they will be read as literals) followed by any single capital letter in the range A to Z (`[A-Z]`) one or more times (`+`). By specifying that the regular expression must locate a capital letter at the start of the call number, the regular expression will not edit the call numbers that begin with a digit.
8082
- The second group `(\d.*)` will match any digit (`\d`) followed by any character (`.`) zero or more times (`*`)
8183

8284
5. In the Replace box enter `$1 $2`
@@ -86,6 +88,15 @@ The Find and Replace tool is another useful way to identify and manipulate data
8688
8. Verify your results look as expected, close preview tab and then click Process
8789

8890

91+
::::::::::::::::::::::::::::::::::::::::::::::::::
92+
93+
::::::::::::::::::::::::::::::::::::::::: callout
94+
95+
### Using a Regex Tester
96+
97+
While the MarcEditor provides a way to preview the results of your regular expression, you can also use a regex tester such as [Regex101](https://regex101.com/). A live regex tester allows you to copy in sample data and then build a regular expression to manipulate that test data. The tester is especially helpful because it provides an explanation of how the regular expression is working on your data, as well as built in quick references for common regex syntax and functions.
98+
99+
89100
::::::::::::::::::::::::::::::::::::::::::::::::::
90101

91102
### Select Records for Edit

0 commit comments

Comments
 (0)