Questions
5 of 30
1What is the purpose of using regular expressions (REGEXP) in MySQL?
2What is the difference between the LIKE operator and the REGEXP operator?
3How do you use the REGEXP operator in a SELECT query?
4What does the caret (^) symbol mean in a MySQL regular expression?
5What does the dollar sign ($) mean in a MySQL REGEXP pattern?
6What does the dot (.) symbol match in a MySQL regular expression?
7How can you use REGEXP to find values starting with a particular letter (e.g., names starting with ‘A’)?
8What is the difference between REGEXP and RLIKE in MySQL?
9How can you perform a case-insensitive REGEXP search in MySQL?
10How do you check if a column value contains only numeric characters using REGEXP?
11How can you use square brackets [ ] in REGEXP patterns to match a range of characters?
12What is the use of the pipe (|) symbol in MySQL REGEXP patterns?
13How do quantifiers like *, +, and ? work in MySQL regular expressions?
14How can you find strings containing specific words using REGEXP (for example, “cat” or “dog”)?
15How do you use {m,n} quantifiers in MySQL REGEXP to match a specific number of occurrences?
16Explain how you can use character classes such as [0-9], [A-Za-z], or [:digit:] in MySQL REGEXP.
17What is the difference between [A-Z] and [[:upper:]] in MySQL REGEXP?
18How can you extract records where a string contains multiple words separated by spaces using REGEXP?
19What happens when you use REGEXP on columns that contain NULL values?
20Can you use REGEXP with the NOT operator? Give an example.
21How does MySQL handle regular expressions internally (regex engine type and case sensitivity)?
22What’s the difference between REGEXP in MySQL 5.x and REGEXP in MySQL 8.0 (which uses ICU-based regex)?
23How can you use the REGEXP_REPLACE() function introduced in MySQL 8.0?
24Explain how REGEXP_INSTR() differs from LOCATE() and INSTR() functions.
25How can you validate email addresses or phone numbers using REGEXP in MySQL?
26What are the performance implications of using REGEXP on large text columns, and how can you optimize it?
27How can you use REGEXP in conjunction with other clauses like WHERE, GROUP BY, or CASE?
28Can you combine multiple REGEXP conditions using logical operators (AND/OR)? Show an example.
29How does MySQL REGEXP handle Unicode characters and multibyte character sets like UTF-8?
30When should you prefer REGEXP over full-text search or LIKE, and when should you avoid it?
05 / 30

What does the dollar sign ($) mean in a MySQL REGEXP pattern?

Understanding the Dollar Sign ($) Symbol in MySQL REGEXP

In MySQL regular expressions, the dollar sign $ is an anchor that matches the end of a string. It ensures that the pattern preceding the $ occurs at the end of the string.

Key Points About the Dollar Sign ($) Symbol
  1. 1

    End Anchor: pattern$ matches strings that end with the specified pattern.

  2. 2

    Position-Specific Matching: Unlike simple substring matching, $ ensures the match occurs at the very end of the string.

  3. 3

    Combining with Character Classes: You can use it with brackets, e.g., [0-9]{4}$ matches strings ending with four digits.

  4. 4

    Use in Validation: Useful for validating formats that must end in a specific way, such as file extensions, postal codes, or numeric codes.

When used in a SELECT query with REGEXP, $ helps narrow down matches to strings ending with specific characters or patterns.

Example: Match Emails Ending with '.com'
Example: Match Phone Numbers Ending with '00'
Difficulty: 5/10
Topics: REGEXP syntax, pattern anchoring, MySQL regex behavior

Scenario Questions

0-2 years experience
  1. 1

    You need to write a query that returns rows where the email column ends with '.org'. How would you use the $ anchor in a MySQL REGEXP pattern to achieve that?

  2. 2

    If you run SELECT * FROM users WHERE username REGEXP 'admin$'; what rows will be matched and why?

  3. 3

    What would happen if you omitted the $ in the previous pattern—how would the result set change?

2-5 years experience
  1. 1

    Your team notices that a query using REGEXP 'error$' is missing some log entries that actually end with 'error' but have a trailing newline character. Explain why this is happening and how you would fix it.

  2. 2

    During a migration to MySQL 8.0, a stored procedure that relied on REGEXP patterns with $ started returning unexpected rows. What changes in regex handling could cause this, and how would you debug it?

  3. 3

    You need to filter product codes that must end with exactly three digits. Write the REGEXP pattern and discuss any trade‑offs regarding index usage.

5-8 years experience
  1. 1

    Design a logging aggregation service that stores raw log lines in MySQL and allows users to define custom REGEXP filters, including end‑of‑line anchors. What performance considerations arise from using $ in patterns, and how would you mitigate them at scale?

  2. 2

    Your production system experiences a slowdown when many users run queries with REGEXP patterns that include $ on a large table. Explain why $ can affect query planning and propose architectural changes (e.g., generated columns, full‑text indexes) to improve throughput.

  3. 3

    How would you ensure that regex patterns with $ behave consistently across different MySQL versions and collations in a multi‑region deployment?

8+ years experience
  1. 1

    The company is moving from MySQL to a distributed SQL platform that supports a different regex engine. How would you approach a migration strategy that preserves the semantics of $ anchors in existing queries, and what tooling or testing would you put in place?

  2. 2

    Across several microservices, teams have built feature flags that rely on MySQL REGEXP patterns with $ to match request URLs. As a staff engineer, how would you standardize pattern definitions to avoid bugs and support future refactoring to a centralized rule engine?

  3. 3

    Discuss the long‑term maintenance implications of embedding $‑anchored regexes directly in application code versus abstracting them into configuration, considering version upgrades and observability.

Follow-up Questions

  • How would you verify that your $‑anchored pattern works for edge cases like trailing whitespace?
  • What impact does using $ have on MySQL's ability to use indexes for REGEXP queries?
  • Can you describe a situation where $ might not behave as expected due to data encoding or collation?