I have a problem solving this: http://regexone.com/lesson/13
I was trying to do something like: (\d+x\d+)
but why it doesn’t work? How do we use “grouping” anyway? Thanks!
input text required capturing group result
1280x720 1280, 720
1920x1600 1920, 1600
1024x768 1024, 768
The exercise is about capturing groups. The requirement is to capture two sequences of digits separately, and skip the
x, like this:Your solution, on the other hand, captures the entire input into a single capturing group denoted by parentheses.
The concept of capturing groups is very important when you need to process individual parts of the input captured by your regular expression, as opposed to processing the entire capture. In the examples at your link, you can grab the first group for the horizontal component of the resolution, and the second group for the vertical component of the resolution. Without two separate capturing groups you would need to find
xin your code, and do an additional split.