-1

I don't understand this part of a long regex:

(?i)(jpg|jpeg|gif|png)(?-i)\z/

What are the parenthesis for again? Is it a capture group? What is the i flag in the capture group for?

I think the only parts I understand are the | and the \z at the end.

Jwan622
  • 11,015
  • 21
  • 88
  • 181

1 Answers1

1

In Ruby

(?i) - start case sensitive mode

(jpg|jpeg|gif|png) - Capturing group to select from any of them (Case insensitive)

(?-i) - end case sensitive mode (only the part between (?i) and (?-i) is case insensitive)

Regex Breakdown

(?i) #Start of case insensitive mode (Whatever follows will be matched irrespective of being lower case or upper case)
  (  #Capturing group
    jpg|
    jpeg|  #Select any one of them
    gif|
    png
  )  #End of capturing group
(?-i) #End of case insensitive mode
\z  #Can match after line break
rock321987
  • 10,942
  • 1
  • 30
  • 43