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
https://forums.phpfreaks.com/topic/90640-regex-pattern/
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
https://forums.phpfreaks.com/topic/90640-regex-pattern/#findComment-464934
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.