Move images into certain folder structure based on names [closed]

Example :

Before sorting:

image_1.jpg
image_2.jpg
image_3.jpg
image_4 number.jpg
image_5.jpg
image_6.jpg
imaget_7.jpg
image_8.jpg
image_9 number.jpg
image_10.jpg
image_11.jpg
image_12.jpg
image_13.jpg
image_14.jpg
image_15 number.jpg

Process:

  1. The sorting process identifies image_4 number.jpg as the last file in the sequence with a space in its name.
  2. It takes the part of the file name before the first space: image_4.
  3. It creates a new folder named image_4.
  4. It moves image_1.jpg, image_2.jpg, and image_3.jpg into the new image_4 folder.

After sorting:

image_4 (folder)
    image_1.jpg
    image_2.jpg
    image_3.jpg
image_4 number.jpg (remains in the original location)
image_9 (folder)
    image_5.jpg
    image_6.jpg
    imaget_7.jpg
    image_8.jpg
image_9 number.jpg (remains in the original location)
image_15 (folder)
    image_10.jpg
    image_11.jpg
    image_12.jpg
    image_13.jpg
    image_14.jpg
image_15 number.jpg (remains in the original location)