-1

I am currently debugging an old script and trying to understand a regex in an SQL query.

What would be the result of this search?

[...] REGEXP '(^| |"|\\()ORDER(-| )[[:digit:]]{3}';
GMB
  • 188,822
  • 23
  • 52
  • 100
lala_12
  • 121
  • 2
  • 10
  • It's the same as `(^|[ "(])ORDER[- ]\d{3}`; It's matching any string that either starts with ORDER or contains the word ORDER after a space, `"` or `(`; and is followed by either `-` or a space and then 3 digits. – ctwheels Dec 03 '19 at 22:06
  • Does this answer your question? [Learning Regular Expressions](https://stackoverflow.com/questions/4736/learning-regular-expressions) – ctwheels Dec 03 '19 at 22:08
  • Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Nick Dec 03 '19 at 22:13

1 Answers1

2

Here is a part by part explanation:

  • (^| |"|\\(): either the beginning of the string (^), or a space, or a double quote, or an opening parenthese (this character needs to be escaped because it is meaningful in regexes)

  • ORDER: the word "ORDER"

  • (-| ): either a dash or a space

  • [[:digit:]]{3}: a sequence of 3 consecutive digits (between 0 and 9)

GMB
  • 188,822
  • 23
  • 52
  • 100
  • Please elaborate on the anonymous downvote: what is wrong with this accepted answer? – GMB Dec 03 '19 at 23:48