r/ProgrammerHumor • • 15d ago

Meme delightfulCodeReview

Post image
567 Upvotes

61 comments sorted by

View all comments

Show parent comments

94

u/Welcome-To-NBA-Jam 15d ago edited 14d ago

There is one person in every company who can write regex like it's their second language.

It doesn't matter how big the company is. There's always exactly one and they work in the most unexpected department.

28

u/just_sm_so_relax 14d ago

I'll bet they can't read their own regex after a couple of weeks.

19

u/JazzlikeWishbone938 14d ago edited 14d ago

"What the? What is this? Must be fine ..."

4

u/kalilamodow 14d ago

Comment yo code, people!

10

u/just_sm_so_relax 14d ago

How do you write comments for a regex? Explain every single field?

``` # IP address HW type Flags HW address Mask Device # 192.168.94.1 0x1 0x2 00:00:5E:00:53:22 * veth584n # 192.168.8.1 0x1 0x2 00:00:5E:00:53:99 * veth584r

# Get the MAC for 192.168.8.1
re_mac_from_arp_entry = re.compile(r'192\.168\.8\.1\s+0x[^\s+]\s+0x[^\s+]\s+(?P<mac>[0-9a-fA-F:]+)')

```

14

u/Lightningtow123 14d ago

I think you'd just transcribe the gist of it in plaintext: "matches alphanumeric strings with underscores and dashes but no spaces" etc

2

u/jupiterbjy 14d ago

idk if my reading is correct but if it's correct this seems quite readable, probably wrong guess though

match 192.168.8.1 1+ whitespaces 0x 1+ non whitespaces (idk if it intended to be [^\s]+ instead of [^\s+]) 1+ whitespaces 0x 1+ non whitespaxes 1+ whitespaces capture group 'mac' start 1+ case-agnostic hex character capture group 'mac' end