Support Desk

About Us Contact Support Sign In

Configuration File - How to Build Regexes

Regular expressions (regex or regexp) are powerful tools used for pattern matching within text. 
They allow you to search, match, and manipulate strings based on specific patterns rather than fixed values. Regular expressions are widely used in programming, text processing, and data validation.


Key Concepts of Regular Expressions

  1. Literals:
Characters that match themselves.
    • Example: cat matches the word "cat" exactly.
  • Metacharacters:
Special characters with specific meanings:
    • .: Matches any character except a newline.
    • ^: Matches the start of a line.
    • $: Matches the end of a line.
    • \: Escape character, used to treat metacharacters as literals.
    • |: OR operator (e.g., cat|dog matches either "cat" or "dog").
  • Character Classes:
Used to match any one of a set of characters.
    • [abc]: Matches any one of "a", "b", or "c".
    • [^abc]: Matches any character except "a", "b", or "c".
    • [0-9]: Matches any digit from 0 to 9.
    • \d: Shortcut for [0-9] (matches any digit).
    • \w: Matches any word character (letters, digits, underscores).
    • \s: Matches any whitespace character (spaces, tabs, newlines).
  • Quantifiers:
Indicate how many times a character or group should appear.
    • *: Zero or more times (e.g., ab* matches "a", "ab", "abb", etc.).
    • +: One or more times (e.g., ab+ matches "ab", "abb", but not "a").
    • ?: Zero or one time (e.g., colou?r matches "color" or "colour").
    • {n}: Exactly n times (e.g., a{3} matches "aaa").
    • {n,}: At least n times (e.g., a{2,} matches "aa", "aaa", etc.).
    • {n,m}: Between n and m times (e.g., a{2,4} matches "aa", "aaa", or "aaaa").
  • Groups and Capturing:
Parentheses () group parts of a pattern and capture matched text.
    • Example: (ab)+ matches one or more repetitions of "ab".
    • Captured groups can be referenced using \1, \2, etc.
  • Assertions:
Define conditions for matches without consuming characters.
    • Lookahead: (?=pattern) ensures a pattern follows.
    • Negative Lookahead: (?!pattern) ensures a pattern does NOT follow.
    • Lookbehind: (?<=pattern) ensures a pattern precedes.
    • Negative Lookbehind: (?<!pattern) ensures a pattern does NOT precede.
    • \b: Word boundary (matches between word and non-word characters).
    • \B: Non-word boundary.

Example with ICD 10

ICD-10 (International Classification of Diseases, 10th Revision) codes are used for medical diagnoses and health conditions. They follow a specific pattern: a letter followed by numbers, often with optional decimal places for more precision.


ICD-10 Code Pattern

A typical ICD-10 code follows this format:
[A-Z][0-9]{2}(\.[0-9]{1,4})?
Here's how the pattern breaks down:
  • [A-Z]: The first character is always an uppercase letter representing the chapter of the diagnosis.
  • [0-9]{2}: The next two characters are numeric, indicating the condition's category.
  • (\.[0-9]{1,4})?: An optional decimal point followed by 1 to 4 digits for specificity.

ICD-10 Example Codes

  1. J45.909 – Asthma, unspecified, uncomplicated.
  2. E11.9 – Type 2 diabetes mellitus without complications.
  3. I10 – Essential (primary) hypertension.
  4. S72.001A – Fracture of unspecified part of neck of right femur, initial encounter.
  5. F32.0 – Major depressive disorder, single episode, mild.

Regex to Match ICD-10 Codes

To match ICD-10 codes using regular expressions:

[A-Z]\d{2}(\.\d{1,4})?
Explanation:
  • [A-Z]: One uppercase letter (A to Z).
  • \d{2}: Exactly two digits.
  • (\.\d{1,4})?: Optional decimal point followed by 1 to 4 digits.

Example Matches

For the pattern "[A-Z]\d{2}(\.\d{1,4})?", the following would match:
  • J45.909
  • E11.9
  • I10
  • S72.001A


Example with ICD 10 Cervical Cancer 

The ICD-10 code for cervical cancer depends on the specific type and stage of the condition. The most commonly used ICD-10 code for malignant neoplasm of the cervix uteri (cervical cancer) is:


Primary ICD-10 Code for Cervical Cancer

  • C53.9 – Malignant neoplasm of cervix uteri, unspecified.

More Specific ICD-10 Codes for Cervical Cancer

  1. C53.0 – Malignant neoplasm of endocervix.
  2. C53.1 – Malignant neoplasm of exocervix.
  3. C53.8 – Malignant neoplasm of overlapping sites of cervix uteri.
  4. C53.9 – Malignant neoplasm of cervix uteri, unspecified.

Regex to Match Cervical Cancer ICD-10 Codes

To match cervical cancer ICD-10 codes using regular expressions, you can use:
C53\.\d
Explanation:
  • C53 – The code for cervical cancer.
  • \. – A literal dot.
  • \d – One digit (0, 1, 8, 9 for the specific subcategories).


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.