Jump to content

Regex Pattern


PutterPlace

Recommended Posts

I was given a regex pattern by a friend. I would like to know exactly what this pattern is looking for. I'm not very good at interpreting these. Here is the pattern given to me:

 

^\s*OK\s*\|\s*([a-f0-9]+)\s*\|\s*([a-f0-9]+)\s*$

 

I removed the beginning and trailing quotes because they aren't necessary at this point.

Link to comment
Share on other sites

NODE                    EXPLANATION

----------------------------------------------------------------------

  ^                        the beginning of the string

----------------------------------------------------------------------

  \s*                      whitespace (\n, \r, \t, \f, and " ") (0 or

                          more times (matching the most amount

                          possible))

----------------------------------------------------------------------

  OK                      'OK'

----------------------------------------------------------------------

  \s*                      whitespace (\n, \r, \t, \f, and " ") (0 or

                          more times (matching the most amount

                          possible))

----------------------------------------------------------------------

  \|                      '|'

----------------------------------------------------------------------

  \s*                      whitespace (\n, \r, \t, \f, and " ") (0 or

                          more times (matching the most amount

                          possible))

----------------------------------------------------------------------

  (                        group and capture to \1:

----------------------------------------------------------------------

    [a-f0-9]+                any character of: 'a' to 'f', '0' to '9'

                            (1 or more times (matching the most

                            amount possible))

----------------------------------------------------------------------

  )                        end of \1

----------------------------------------------------------------------

  \s*                      whitespace (\n, \r, \t, \f, and " ") (0 or

                          more times (matching the most amount

                          possible))

----------------------------------------------------------------------

  \|                      '|'

----------------------------------------------------------------------

  \s*                      whitespace (\n, \r, \t, \f, and " ") (0 or

                          more times (matching the most amount

                          possible))

----------------------------------------------------------------------

  (                        group and capture to \2:

----------------------------------------------------------------------

    [a-f0-9]+                any character of: 'a' to 'f', '0' to '9'

                            (1 or more times (matching the most

                            amount possible))

----------------------------------------------------------------------

  )                        end of \2

----------------------------------------------------------------------

  \s*                      whitespace (\n, \r, \t, \f, and " ") (0 or

                          more times (matching the most amount

                          possible))

----------------------------------------------------------------------

  $                        before an optional \n, and the end of the

                          string

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.