-4

Can someone explain to me step-by-step how the regex below works?

'\([^)]*\)
J0e3gan
  • 8,287
  • 9
  • 48
  • 76
Maximus S
  • 9,379
  • 18
  • 67
  • 140

3 Answers3

1

Visual

visual

Description

  • ' - literal ' (single quote) character
  • \( - literal ( (left bracket) character
  • [^)]* - 0 or more of any character except ) (right bracket)
  • \) - literal ) (right bracket) character

Tho there's nothing complicated here. It's all something you could've learned in 10 minutes on a site like http://www.regular-expressions.info/ or something similar

Thank you
  • 107,507
  • 28
  • 191
  • 224
1

Match...

  • '...a single apostrophe...
  • \(...followed by a single left paren... (the \ being to escape the (, which is otherwise treated as a special (begin-grouping) character)
  • [^)]*...followed by zero or more (*) characters in the class ([...]) "not )"... (where the opening ^ indicates "not")
  • \)...followed by a single right paren. (the \ being to escape the ), which is otherwise treated as a special (end-grouping) character)

Check out regex101 or Debuggex to get such explanations automatically.

For example, I pasted your regex into regex101 and got the following explanation of it immediately:

regex101 Explanation of Your Regex

Pasting it into a Debuggex demo yielded the following graphical explanation:

Debuggex Visualization of Your Regex

Also, be clear what regex dialect you are using (e.g. JavaScript, PCRE etcetera) because it can make a difference in what (more complicated) regexes mean.

With these sorts of tools and further reading, you should be well on your way to generally answering these sorts of questions for yourself.

J0e3gan
  • 8,287
  • 9
  • 48
  • 76
0

' single quote followed by a

( note: in here it's escaped by a \ to signify a literal

followed by what's not inside [] zero or more times the caret ^ is used to signify negation and the [] signifies a range of characters for example a-z, the * means zero or more of the previous thing

followed by a literal ) again it's escaped here by a \

A simple and quick tutorial on this perl site.

Robert Rocha
  • 8,656
  • 15
  • 59
  • 110