I’m trying to extract 4 chunks of information from a string. The string is the name of a file with the extension included. The first group can contain any valid characters until the space before the second group is reached. The second group of data will be 4 numbers contained inside of a set of square brackets. That group is separated by the first group by a space. The third group could be either 3 or 4 numbers followed by the letter “p”. This groups is also separated by a space from the previous group. The last group is simply the file extension.
Here’s an example:
This, could be ['a'] s(@m)pl3 file name_with any characters [1923] (720p).avi
That would then need to be parsed to be:
$1 = This, could be ['a'] s(@m)pl3 file name_with any characters
$2 = 1923
$3 = 720p
$4 = avi
See also perldoc perlreref.
Here is an updated example to take into account your sample string:
Output: