Skip to content

Instantly share code, notes, and snippets.

@aMcCode
aMcCode / Find-Text-In-Single-Quotes-Regex.md
Last active August 15, 2022 06:32
Using Regex to Find All Text in Single Quotes

Matching All Text in Single Quotes

In my daily work, I am required to parse text generated by various systems. One such system generates a data entry audit trail with output that looks like the text below. When I need to compare the old value entered to the new value entered for a given datapoint, I search the audit trail for the latest entry prior to the current entry based on an an audit date. Once I have that specific audit entry, I search for the specific data entered. Since I can count on the validated system that produces the audit trail to output the audit entry in a specific way, i.e. "User entered 'some value'", I can use regex to extract the value. I also need to find where the user has entered an empty value.

The purpose of this tutorial is to detail how, ((?<=\').*(?=\'))|(User entered empty\.), the regex or regular expression pattern for this specific search works.

Sample Text

User entered '01 Jan 2019'
User entered 'Grade 2: Moderate (GRADE 2)'