regex - How do the curly braces work in this Ruby Split line -
this question has answer here:
- reference - regex mean? 1 answer
i have been recommended following line of code use on text file:
arr = str.split(/\n{2,}/).map { |s| s.split(/\n/) } am trying understand how the:
(/\n{2,}/) part working , does.
the leading , trailing / mark beginning , end of regular expression. \n match single newline. {2,} after symbol (in case \n) match occurrence of symbol repeated 2 or more times, in case 2 or more consecutive newlines. had been \n{3,6}, match consecutive newlines repeated between 3 , 6 times.
Comments
Post a Comment