Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby regex not ignoring whitespace

Tags:

regex

ruby

Matching S01E01 in Ruby

with

/S\d+?E\d+?/ix

which works, however, S01 E01 does not. I thought the /x should ignore white spaces?

like image 802
daemonza Avatar asked Mar 19 '26 21:03

daemonza


1 Answers

/x ignores whitespace inside your regex, not in the text you're matching.

You're looking for

/S\d+?\s*E\d+?/i
like image 132
Dogbert Avatar answered Mar 21 '26 20:03

Dogbert