[PATCH] D28384: Update update_test_checks to work properly with phi nodes and other fun things.

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 6 15:29:20 PST 2017


dberlin added a comment.

In https://reviews.llvm.org/D28384#638258, @dberlin wrote:

> > If you want to use sub, you have to capture the other groups so you can put the entire match back together (or call replace on group 0, which is equivalent to what i was doing before, just more verbose)
>
> Sorry, you can also use non-capturing groups i believe (using ?:), but this makes the regexp even uglier
>
> (I could also use backreferences in the replacement string, but i like being explicit)


Unfortunately, it looks like sub has non-intuitive behavior here.
The non-capturing groups definitely cause the match group to change, but sub still replaces the entire regex:

In [10]: def foo(match):

  ...:     print(match.groups())
  ...:     return "12345"
  ...:

In [11]: matcher = re.compile('(?:\s+)(aaaaaa)(?:\s+)')
In [12]: matcher.sub(foo, "                aaaaaa            ")
('aaaaaa',)
Out[12]: '12345'


https://reviews.llvm.org/D28384





More information about the llvm-commits mailing list