3 deleted 645 characters in body
source | link

Java 8, 72 7171 67 62 bytes

s->s.replaceAll("(^|(?<=(^.*)))( ?)(\\S+) ?(?=( .+*$)|$)","$2$3\"$4\"$5\n""$1\"$2\" $3\n")

Try it online.Try it online.

(^|(?<=(^.*)))( ?)(\\S+) ?(?=( .+*$)|$)   # === MATCH ===
( |          )                        # Start with either:
 ^                                    #  The start of the string
  |                                   #  OR
   (?<=     )                         #  A positive look-behind to:
        ^.*                           #   The optional leading portion of the string
       (   )                          #   (which is captured in capture group 2
                ?                     # Followed by an optional space
              (  )                    # (which is captured in capture group 31)
                   \\S+               # Followed by one or more non-space characters,
                                      # so the next word in line
                  (    )              # (which is captured in capture group 42)
                  ?      (?=     | )   # Followed by a positive look-aheadan tooptional either:space
                            (?= .*    )   #  A space, followedFollowed by onea orpositive morelook-ahead charactersto:
                           (   ) .*$     #  (whichThe istrailing capturedoptional inportion captureof groupthe 5)string
                              (  | )    #  OR
                                 $    #(which is Thecaptured endin ofcapture thegroup string3)

$2$3\"$4\"$5\n      $1\"$2\" $3\n                 # === REPLACEMENT ===
$2        $1                            # The match of capture group 21
                                      # (the leading portion)
  $3          $2                        # Followed by the match of capture group 32
                                      # (the optional space)
      $4                              #current Followedword byin the match of capture group 4'iteration'),
              \"  \"                      # (the current wordsurrounded inby thequotation 'iteration'),marks
    \"  \"                            # surroundedFollowed by quotation marks
      a space character
  $5       $3                   # Followed by the match of capture group 53
                                      # (the trailing portion)
            \n                        # Followed by a trailing newline

Java 8, 72 71 bytes

s->s.replaceAll("(^|(?<=(^.*)))( ?)(\\S+)(?=( .+)|$)","$2$3\"$4\"$5\n")

Try it online.

(^|(?<=(^.*)))( ?)(\\S+)(?=( .+)|$)   # === MATCH ===
( |          )                        # Start with either:
 ^                                    #  The start of the string
  |                                   #  OR
   (?<=     )                         #  A positive look-behind to:
        ^.*                           #   The leading portion of the string
       (   )                          #   (which is captured in capture group 2
                ?                     # Followed by an optional space
              (  )                    # (which is captured in capture group 3)
                   \\S+               # Followed by one or more non-space characters,
                                      # so the next word in line
                  (    )              # (which is captured in capture group 4)
                        (?=     | )   # Followed by a positive look-ahead to either:
                             .*       #  A space, followed by one or more characters
                           (   )      #  (which is captured in capture group 5)
                                |     #  OR
                                 $    #  The end of the string

$2$3\"$4\"$5\n                        # === REPLACEMENT ===
$2                                    # The match of capture group 2
                                      # (the leading portion)
  $3                                  # Followed by the match of capture group 3
                                      # (the optional space)
      $4                              # Followed by the match of capture group 4
                                      # (the current word in the 'iteration'),
    \"  \"                            # surrounded by quotation marks
          $5                          # Followed by the match of capture group 5
                                      # (the trailing portion)
            \n                        # Followed by a trailing newline

Java 8, 72 71 67 62 bytes

s->s.replaceAll("(?<=(^.*))(\\S+) ?(?=(.*$))","$1\"$2\" $3\n")

Try it online.

(?<=(^.*))(\\S+) ?(?=(.*$))   # === MATCH ===
(?<=     )                    # A positive look-behind to:
     ^.*                      #  The optional leading portion of the string
    (   )                     #  (which is captured in capture group 1)
           \\S+               # Followed by one or more non-space characters,
                              # so the next word in line
          (    )              # (which is captured in capture group 2)
                 ?            # Followed by an optional space
                  (?=     )   # Followed by a positive look-ahead to:
                      .*$     #  The trailing optional portion of the string
                     (   )    #  (which is captured in capture group 3)

$1\"$2\" $3\n                 # === REPLACEMENT ===
$1                            # The match of capture group 1
                              # (the leading portion)
    $2                        # Followed by the match of capture group 2
                              # (the current word in the 'iteration'),
  \"  \"                      # surrounded by quotation marks
                              # Followed by a space character
         $3                   # Followed by the match of capture group 3
                              # (the trailing portion)
           \n                 # Followed by a trailing newline
2 edited body
source | link
s->                    // Method with String as both parameter and return-type:
  s.replaceAll("...",  //  Replace all matches in this regex
               "...")  //  With this
                       //  And then return the result
(^|(?<=(^.*)))( ?)(\\S+)(?=( .+)|$)   # === MATCH ===
( |          )                        # Start with either:
 ^                                    #  The start of the string
  |                                   #  OR
   (?<=     )                         #  A positive look-behind to:
       ( ^.*)                           #   The leading portion of the string
         (   )                          #   (which is captured in capture group 2
              (  ?)                     # Followed by an optional space
                (  )                    # (which is captured in capture group 3)
                  ( \\S+)               # Followed by one or more non-space characters,
                                      # so the next word in line
                    (    )              # (which is captured in capture group 4)
                        (?=     | )   # Followed by a positive look-ahead to either:
                           (  .*)       #  A space, followed by one or more characters
                             (   )      #  (which is captured in capture group 5)
                                |     #  OR
                                 $    #  The end of the string

$2$3\"$4\"$5\n                        # === REPLACEMENT ===
$2                                    # The match of capture group 2
                                      # (the leading portion)
  $3                                  # Followed by the match of capture group 3
                                      # (the optional space)
      $4                              # Followed by the match of capture group 4
                                      # (the current word in the 'iteration'),
    \"  \"                            # surrounded by quotation marks
          $5                          # Followed by the match of capture group 5
                                      # (the trailing portion)
            \n                        # Followed by a trailing newline
s->                    // Method with String as both parameter and return-type:
  s.replaceAll("...",  //  Replace all matches in this regex
               "...")  //  With this
                       //  And then return the result
(^|(?<=(^.*)))( ?)(\\S+)(?=( .+)|$)   # MATCH
( |          )                        # Start with either:
 ^                                    #  The start of the string
  |                                   #  OR
   (?<=     )                         #  A positive look-behind to:
       (^.*)                          #   The leading portion of the string
                                      #   (which is captured in capture group 2
              ( ?)                    # Followed by an optional space
                                      # (which is captured in capture group 3)
                  (\\S+)              # Followed by one or more non-space characters,
                                      # so the next word in line
                                      # (which is captured in capture group 4)
                        (?=     | )   # Followed by a positive look-ahead to either:
                           ( .*)      #  A space, followed by one or more characters
                                      #  (which is captured in capture group 5)
                                |     #  OR
                                 $    #  The end of the string

$2$3\"$4\"$5\n                        # REPLACEMENT
$2                                    # The match of capture group 2
                                      # (the leading portion)
  $3                                  # Followed by the match of capture group 3
                                      # (the optional space)
      $4                              # Followed by the match of capture group 4
                                      # (the current word in the 'iteration'),
    \"  \"                            # surrounded by quotation marks
          $5                          # Followed by the match of capture group 5
                                      # (the trailing portion)
            \n                        # Followed by a trailing newline
s->                    // Method with String as both parameter and return-type
  s.replaceAll("...",  //  Replace all matches in this regex
               "...")  //  With this
                       //  And then return the result
(^|(?<=(^.*)))( ?)(\\S+)(?=( .+)|$)   # === MATCH ===
( |          )                        # Start with either:
 ^                                    #  The start of the string
  |                                   #  OR
   (?<=     )                         #  A positive look-behind to:
        ^.*                           #   The leading portion of the string
       (   )                          #   (which is captured in capture group 2
                ?                     # Followed by an optional space
              (  )                    # (which is captured in capture group 3)
                   \\S+               # Followed by one or more non-space characters,
                                      # so the next word in line
                  (    )              # (which is captured in capture group 4)
                        (?=     | )   # Followed by a positive look-ahead to either:
                             .*       #  A space, followed by one or more characters
                           (   )      #  (which is captured in capture group 5)
                                |     #  OR
                                 $    #  The end of the string

$2$3\"$4\"$5\n                        # === REPLACEMENT ===
$2                                    # The match of capture group 2
                                      # (the leading portion)
  $3                                  # Followed by the match of capture group 3
                                      # (the optional space)
      $4                              # Followed by the match of capture group 4
                                      # (the current word in the 'iteration'),
    \"  \"                            # surrounded by quotation marks
          $5                          # Followed by the match of capture group 5
                                      # (the trailing portion)
            \n                        # Followed by a trailing newline
1
source | link

Java 8, 72 71 bytes

s->s.replaceAll("(^|(?<=(^.*)))( ?)(\\S+)(?=( .+)|$)","$2$3\"$4\"$5\n")

Try it online.

Explanation:

s->                    // Method with String as both parameter and return-type:
  s.replaceAll("...",  //  Replace all matches in this regex
               "...")  //  With this
                       //  And then return the result

Regex explanation:

(^|(?<=(^.*)))( ?)(\\S+)(?=( .+)|$)   # MATCH
( |          )                        # Start with either:
 ^                                    #  The start of the string
  |                                   #  OR
   (?<=     )                         #  A positive look-behind to:
       (^.*)                          #   The leading portion of the string
                                      #   (which is captured in capture group 2
              ( ?)                    # Followed by an optional space
                                      # (which is captured in capture group 3)
                  (\\S+)              # Followed by one or more non-space characters,
                                      # so the next word in line
                                      # (which is captured in capture group 4)
                        (?=     | )   # Followed by a positive look-ahead to either:
                           ( .*)      #  A space, followed by one or more characters
                                      #  (which is captured in capture group 5)
                                |     #  OR
                                 $    #  The end of the string

$2$3\"$4\"$5\n                        # REPLACEMENT
$2                                    # The match of capture group 2
                                      # (the leading portion)
  $3                                  # Followed by the match of capture group 3
                                      # (the optional space)
      $4                              # Followed by the match of capture group 4
                                      # (the current word in the 'iteration'),
    \"  \"                            # surrounded by quotation marks
          $5                          # Followed by the match of capture group 5
                                      # (the trailing portion)
            \n                        # Followed by a trailing newline