Sublime Forum

[SOLVED] Converting strings in for loop into a list

#1

Hoping somebody can help me

I want to grab the strings in each list between the double quotes and then turn that into a single list. So far I have this.

matches = ['8 "app/Http/Controllers/Controller.php" line 1', '9 "app/Http/Controllers/PostController.php" line 1']

if len(matches) > 1:
    for match in matches:
        matches = re.findall(r'\"(.+?)\"', match)
        print(matches[0])

Which outputs

app/Http/Controllers/Controller.php
app/Http/Controllers/PostController.php

I want to turn it into a list like this

['app/Http/Controllers/Controller.php', 'app/Http/Controllers/PostController.php']

Also it should be dynamic as there can be more than 2 items.

Been stuck on this too long, would appreciate the help :slight_smile:

Edit: This has been solved

0 Likes