# PERL: translate this nasty regex

**URL:** https://boards.straightdope.com/t/perl-translate-this-nasty-regex/355594
**Category:** Factual Questions
**Created:** [May 5, 2006, 8:40pm UTC](https://boards.straightdope.com/t/perl-translate-this-nasty-regex/355594 "2006-05-05T20:40:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Belrix](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@Belrix](https://boards.straightdope.com/u/Belrix)
#### Post date: [May 5, 2006, 8:40pm UTC](https://boards.straightdope.com/t/perl-translate-this-nasty-regex/355594/1 "2006-05-05T20:40:28Z")

</div>

We’re all scratching our heads on this one. We’re trying to figure out what this does:

~(?\>.\*?(?\<!\w{3})(?ix) \s(\S)w(?:he|gf|\x{0159})(?-i:MuG)0V(\w\d))Sb4(?=[[:xdigit:]])\2\1

---

<div class="post-metadata">

### Author: ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)
#### Post date: [May 5, 2006, 9:07pm UTC](https://boards.straightdope.com/t/perl-translate-this-nasty-regex/355594/2 "2006-05-05T21:07:28Z")

</div>

Straight from [YAPE::Regex::Explain](http://search.cpan.org/~pinyan/YAPE-Regex-Explain-3.011/Explain.pm) by my pal **japhy** :

```auto

(?-imsx:~(?>.*?(?<!w{3})(?ix) s(S)w(?:he|gf|?)(?-i:MuG)0V(wd))Sb4(?=[[:xdigit:]]))

matches as follows:
  
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching 
) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  ~ << '~'
----------------------------------------------------------------------
  (?> << match (and do not backtrack afterwards):
----------------------------------------------------------------------
    .*? <<<< any character except 
 (0 or more times
                      <<<< (matching the least amount possible))
----------------------------------------------------------------------
    (?<! <<<< look behind to see if there is not:
----------------------------------------------------------------------
      w{3} <<<<<< 'w' (3 times)
----------------------------------------------------------------------
    ) <<<< end of look-behind
----------------------------------------------------------------------
    (?ix) <<<< set flags for this block (case-
                      <<<< insensitive) (disregarding whitespace
                      <<<< and comments) (with ^ and $ matching
                      <<<< normally) (with . not matching 
)
----------------------------------------------------------------------
    s <<<< 's'
----------------------------------------------------------------------
    ( <<<< group and capture to \1:
----------------------------------------------------------------------
      S <<<<<< 'S'
----------------------------------------------------------------------
    ) <<<< end of \1
----------------------------------------------------------------------
    w <<<< 'w'
----------------------------------------------------------------------
    (?: <<<< group, but do not capture:
----------------------------------------------------------------------
      he <<<<<< 'he'
----------------------------------------------------------------------
     | <<<<< OR
----------------------------------------------------------------------
      gf <<<<<< 'gf'
----------------------------------------------------------------------
     | <<<<< OR
----------------------------------------------------------------------
      ? <<<<<< '?'
                     <<<<<< '
----------------------------------------------------------------------
    ) <<<< end of grouping
----------------------------------------------------------------------
    (?-i: <<<< group, but do not capture (disregarding
                      <<<< whitespace and comments) (case-
                      <<<< sensitive) (with ^ and $ matching
                      <<<< normally) (with . not matching 
):
----------------------------------------------------------------------
      MuG <<<<<< 'MuG'
----------------------------------------------------------------------
    ) <<<< end of grouping
----------------------------------------------------------------------
    0V <<<< '0V'
----------------------------------------------------------------------
    ( <<<< group and capture to \2:
----------------------------------------------------------------------
      wd <<<<<< 'wd'
----------------------------------------------------------------------
    ) <<<< end of \2
----------------------------------------------------------------------
  ) << end of look-ahead
----------------------------------------------------------------------
  Sb4 << 'Sb4'
----------------------------------------------------------------------
  (?= << look ahead to see if there is:
----------------------------------------------------------------------
    [[:xdigit:]] <<<< any character of: hexadecimal digits (a-
                      <<<< f, A-F, 0-9)
----------------------------------------------------------------------
  ) << end of look-ahead
----------------------------------------------------------------------
                      << ' '
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------

```
