Repository: google/yapf
Issue: Extra spaces being added by yapf (ad-infinitum).

Using `yapf 0.20.1` and Python 3.6.4, when I `yapf` the following code:

```python
import yaml

{
   "config": {
           **yaml.load(f"""
    a:
      b: 0""")},
 }
```

yapf adds an extraneous 13 spaces after the closing `"""`:

```
--- test.py	(original)
+++ test.py	(reformatted)
@@ -4,5 +4,5 @@
    "config": {
            **yaml.load(f"""
     a:
-      b: 0""")},
+      b: 0"""             )},
  }
```

Running `yapf` repeatedly just adds even more spaces (ad-infinitum). This does *not* happen if:
- We don't use a format string
- We take out the wrapping `config` dictionary
- We don't use the new dict unpacking `**` syntax.

This also ignores `yapf: disable` comments, so 
```python
import yaml
# yapf: disable
{
   "config": {
           **yaml.load(f"""
    a:
      b: 0""")},
 }
# yapf: enable
```

*still* inserts extra spaces.

Changed files:
yapftests/reformatter_python3_test.py, yapf/yapflib/format_token.py, yapftests/format_token_test.py

diff --git a/yapf/yapflib/format_token.py b/yapf/yapflib/format_token.py
index d225853..d86c16d 100644
--- a/yapf/yapflib/format_token.py
+++ b/yapf/yapflib/format_token.py
@@ -273,9 +273,17 @@ class FormatToken(object):
   @property
   @py3compat.lru_cache()
   def is_multiline_string(self):
+    if py3compat.PY3:
+      prefix = "("
+      prefix += "r|u|R|U|f|F|fr|Fr|fR|FR|rf|rF|Rf|RF"  # strings
+      prefix += "|b|B|br|Br|bR|BR|rb|rB|Rb|RB"  # bytes
+      prefix += ")?"
+    else:
+      prefix = "[uUbB]?[rR]?"
+
+    regex = r'^{prefix}(?P<delim>"""|\\'\\'\\').*(?P=delim)$'.format(prefix=prefix)
     return (self.is_string and
-            re.match(r'^[uUbB]?[rR]?(?P<delim>"""|\\'\\'\\').*(?P=delim)$',
-                     self.value, re.DOTALL) is not None)
+            re.match(regex, self.value, re.DOTALL) is not None)
 
   @property
   @py3compat.lru_cache()
diff --git a/yapftests/format_token_test.py b/yapftests/format_token_test.py
index b3c0dc2..f7b613b 100644
--- a/yapftests/format_token_test.py
+++ b/yapftests/format_token_test.py
@@ -32,6 +32,13 @@ class FormatTokenTest(unittest.TestCase):
     self.assertEqual("FormatToken(name=COMMENT, value=# A comment)", str(tok))
     self.assertTrue(tok.is_comment)
 
+  def testIsMultilineString(self):
+    tok = format_token.FormatToken(pytree.Leaf(token.STRING, '"""hello"""'))
+    self.assertTrue(tok.is_multiline_string)
+
+    tok = format_token.FormatToken(pytree.Leaf(token.STRING, 'r"""hello"""'))
+    self.assertTrue(tok.is_multiline_string)
+
 
 if __name__ == "__main__":
   unittest.main()
diff --git a/yapftests/reformatter_python3_test.py b/yapftests/reformatter_python3_test.py
index fa68c66..7ff01eb 100644
--- a/yapftests/reformatter_python3_test.py
+++ b/yapftests/reformatter_python3_test.py
@@ -354,6 +354,19 @@ class Foo:
     uwlines = yapf_test_helper.ParseAndUnwrap(unformatted_code)
     self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(uwlines))
 
+  def testMultilineFormatString(self):
+    if sys.version_info[1] < 6:
+      return
+    code = """\\
+# yapf: disable
+(f'''
+  ''')
+# yapf: enable
+"""
+    # https://github.com/google/yapf/issues/513
+    uwlines = yapf_test_helper.ParseAndUnwrap(code)
+    self.assertCodeEqual(code, reformatter.Reformat(uwlines))
+
 
 if __name__ == '__main__':
   unittest.main()