Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Finding multiple strings between the two same strings
#1
I'm just starting to learn Python and have hit my first real road block. I have a need for a file renamer and figured it would be a good way to start learning.

I'm trying to extract all of the titles from the following string (Basically each title is between title":" and ","):

{"page":1,"total_results":6,"total_pages":1,"results":[{"vote_count":2312,"id":2789,"video":false,"vote_average":6.4,"title":"The Chronicles of Riddick","popularity":7.467,"poster_path":"\/hVAfGskQdktDwYTqrT7wY1f2M4y.jpg","original_language":"en","original_title":"The Chronicles of Riddick","genre_ids":[28,878],"backdrop_path":"\/AoLVfcYPziZZQbAFQuKoceHreXD.jpg","adult":false,"overview":"After years of outrunning ruthless bounty hunters, escaped convict Riddick suddenly finds himself caught between opposing forces in a fight for the future of the human race. Now, waging incredible battles on fantastic and deadly worlds, this lone, reluctant hero will emerge as humanity's champion - and the last hope for a universe on the edge of annihilation.","release_date":"2004-06-11"},{"vote_count":0,"id":374771,"video":false,"vote_average":0,"title":"The Chronicles of Riddick: Furia","popularity":9.942,"poster_path":"\/lV5qk31axl9mo0uq9L4Jkmuzrbq.jpg","original_language":"en","original_title":"The Chronicles of Riddick: Furia","genre_ids":[878,28],"backdrop_path":null,"adult":false,"overview":"When Riddick finally finds his home planet, he has no idea what's in store for him.","release_date":""},{"vote_count":188,"id":2791,"video":false,"vote_average":6.1,"title":"The Chronicles of Riddick: Dark Fury","popularity":2.059,"poster_path":"\/ewqSDOOyjyODmyuVuxHmKGYKZR9.jpg","original_language":"en","original_title":"The Chronicles of Riddick: Dark Fury","genre_ids":[28,16,878,53],"backdrop_path":"\/jrZbDux6c99QxpxHqnLS6W8Jffc.jpg","adult":false,"overview":"After their narrow escape at the end of \"Pitch Black,\" Riddick, Jack and the Imam find themselves at the mercy of a madwoman who intends to entomb Riddick forever as part of a twisted art exhibit. With little but a shiv and Riddick's innate viciousness to aid them, Riddick and his allies must find a way to escape from their captor and her band of mercenaries.","release_date":"2004-06-15"},{"vote_count":2620,"id":2787,"video":false,"vote_average":6.8,"title":"Pitch Black","popularity":8.883,"poster_path":"\/j4iBVA49KDBX4ypfVcZxl1y7CCT.jpg","original_language":"en","original_title":"Pitch Black","genre_ids":[53,878,28],"backdrop_path":"\/yc0cEEZ9OO6ydyYmCEfY90Q9jII.jpg","adult":false,"overview":"When their ship crash-lands on a remote planet, the marooned passengers soon learn that escaped convict Riddick isn't the only thing they have to fear. Deadly creatures lurk in the shadows, waiting to attack in the dark, and the planet is rapidly plunging into the utter blackness of a total eclipse. With the body count rising, the doomed survivors are forced to turn to Riddick with his eerie eyes to guide them through the darkness to safety. With time running out, there's only one rule: Stay in the light.","release_date":"2000-02-18"},{"vote_count":2845,"id":87421,"video":false,"vote_average":6.2,"title":"Riddick","popularity":15.891,"poster_path":"\/duoN6oNGp1emHkkhlTcY76Wz2ED.jpg","original_language":"en","original_title":"Riddick","genre_ids":[878,28,53],"backdrop_path":"\/mLbjD5xyrjLzVviSd8l37rxfWBo.jpg","adult":false,"overview":"Betrayed by his own kind and left for dead on a desolate planet, Riddick fights for survival against alien predators and becomes more powerful and dangerous than ever before. Soon bounty hunters from throughout the galaxy descend on Riddick only to find themselves pawns in his greater scheme for revenge. With his enemies right where he wants them, Riddick unleashes a vicious attack of vengeance before returning to his home planet of Furya to save it from destruction.","release_date":"2013-09-02"},{"vote_count":49,"id":211449,"video":false,"vote_average":6.7,"title":"Riddick: Blindsided","popularity":1.249,"poster_path":"\/AiWr89Y4g6gkJ3WhVv1TrcSTFMf.jpg","original_language":"en","original_title":"Riddick: Blindsided","genre_ids":[28,16,878],"backdrop_path":"\/7i9W0PzRGbxv8MJ6cYIIkAxyubE.jpg","adult":false,"overview":"This motion comic gaps the bridge between 2004's The Chronicles of Riddick, and 2013's Riddick. A new attempt on Lord Marshal Riddick's life is made on the Necromongers' ship. It's time for Riddick to end the years long meandering through space and go back to his roots.","release_date":"2013-07-26"}]}

I tried the following, but this seems to use the last "," of the string.

regex = '(?<="title":")(.*)(?=",")'
results = re.findall(regex,result)
print(results)
Quote
#2
import re

result = """{"page":1,"total_results":6,"total_pages":1,"results":[{"vote_count":2312,"id":2789,"video":false,"vote_average":6.4,"title":"The Chronicles of Riddick","popularity":7.467,"poster_path":"\/hVAfGskQdktDwYTqrT7wY1f2M4y.jpg","original_language":"en","original_title":"The Chronicles of Riddick","genre_ids":[28,878],"backdrop_path":"\/AoLVfcYPziZZQbAFQuKoceHreXD.jpg","adult":false,"overview":"After years of outrunning ruthless bounty hunters, escaped convict Riddick suddenly finds himself caught between opposing forces in a fight for the future of the human race. Now, waging incredible battles on fantastic and deadly worlds, this lone, reluctant hero will emerge as humanity's champion - and the last hope for a universe on the edge of annihilation.","release_date":"2004-06-11"},{"vote_count":0,"id":374771,"video":false,"vote_average":0,"title":"The Chronicles of Riddick: Furia","popularity":9.942,"poster_path":"\/lV5qk31axl9mo0uq9L4Jkmuzrbq.jpg","original_language":"en","original_title":"The Chronicles of Riddick: Furia","genre_ids":[878,28],"backdrop_path":null,"adult":false,"overview":"When Riddick finally finds his home planet, he has no idea what's in store for him.","release_date":""},{"vote_count":188,"id":2791,"video":false,"vote_average":6.1,"title":"The Chronicles of Riddick: Dark Fury","popularity":2.059,"poster_path":"\/ewqSDOOyjyODmyuVuxHmKGYKZR9.jpg","original_language":"en","original_title":"The Chronicles of Riddick: Dark Fury","genre_ids":[28,16,878,53],"backdrop_path":"\/jrZbDux6c99QxpxHqnLS6W8Jffc.jpg","adult":false,"overview":"After their narrow escape at the end of \"Pitch Black,\" Riddick, Jack and the Imam find themselves at the mercy of a madwoman who intends to entomb Riddick forever as part of a twisted art exhibit. With little but a shiv and Riddick's innate viciousness to aid them, Riddick and his allies must find a way to escape from their captor and her band of mercenaries.","release_date":"2004-06-15"},{"vote_count":2620,"id":2787,"video":false,"vote_average":6.8,"title":"Pitch Black","popularity":8.883,"poster_path":"\/j4iBVA49KDBX4ypfVcZxl1y7CCT.jpg","original_language":"en","original_title":"Pitch Black","genre_ids":[53,878,28],"backdrop_path":"\/yc0cEEZ9OO6ydyYmCEfY90Q9jII.jpg","adult":false,"overview":"When their ship crash-lands on a remote planet, the marooned passengers soon learn that escaped convict Riddick isn't the only thing they have to fear. Deadly creatures lurk in the shadows, waiting to attack in the dark, and the planet is rapidly plunging into the utter blackness of a total eclipse. With the body count rising, the doomed survivors are forced to turn to Riddick with his eerie eyes to guide them through the darkness to safety. With time running out, there's only one rule: Stay in the light.","release_date":"2000-02-18"},{"vote_count":2845,"id":87421,"video":false,"vote_average":6.2,"title":"Riddick","popularity":15.891,"poster_path":"\/duoN6oNGp1emHkkhlTcY76Wz2ED.jpg","original_language":"en","original_title":"Riddick","genre_ids":[878,28,53],"backdrop_path":"\/mLbjD5xyrjLzVviSd8l37rxfWBo.jpg","adult":false,"overview":"Betrayed by his own kind and left for dead on a desolate planet, Riddick fights for survival against alien predators and becomes more powerful and dangerous than ever before. Soon bounty hunters from throughout the galaxy descend on Riddick only to find themselves pawns in his greater scheme for revenge. With his enemies right where he wants them, Riddick unleashes a vicious attack of vengeance before returning to his home planet of Furya to save it from destruction.","release_date":"2013-09-02"},{"vote_count":49,"id":211449,"video":false,"vote_average":6.7,"title":"Riddick: Blindsided","popularity":1.249,"poster_path":"\/AiWr89Y4g6gkJ3WhVv1TrcSTFMf.jpg","original_language":"en","original_title":"Riddick: Blindsided","genre_ids":[28,16,878],"backdrop_path":"\/7i9W0PzRGbxv8MJ6cYIIkAxyubE.jpg","adult":false,"overview":"This motion comic gaps the bridge between 2004's The Chronicles of Riddick, and 2013's Riddick. A new attempt on Lord Marshal Riddick's life is made on the Necromongers' ship. It's time for Riddick to end the years long meandering through space and go back to his roots.","release_date":"2013-07-26"}]}"""


regex = '(?<="title":")(.*?)","'
results = re.findall(regex, result)
print(results)
Output:
['The Chronicles of Riddick', 'The Chronicles of Riddick: Furia', 'The Chronicles of Riddick: Dark Fury', 'Pitch Black', 'Riddick', 'Riddick: Blindsided']
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  What is wrong with this strings comparison minh 3 158 Jan-31-2020, 07:42 PM
Last Post: minh
  Iterating through a list of strings Ash_Ren 1 163 Nov-22-2019, 08:30 PM
Last Post: buran
  How do I delete symbols in a list of strings? Than999 1 186 Nov-16-2019, 09:37 PM
Last Post: ibreeden
  Split a long string into other strings with no delimiters/characters krewlaz 4 185 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  convert strings of date to datetime exported from CSV GiorgosPap31 1 171 Oct-31-2019, 02:37 PM
Last Post: buran
  f-strings and backslashes newbieAuggie2019 5 436 Oct-26-2019, 06:58 AM
Last Post: buran
  A doubt with 'in' and 'not in' operators with strings newbieAuggie2019 7 313 Oct-23-2019, 03:11 PM
Last Post: perfringo
  colouring strings newbieAuggie2019 23 1,262 Oct-23-2019, 08:59 AM
Last Post: newbieAuggie2019
  Back again on f-strings newbieAuggie2019 11 518 Oct-16-2019, 11:24 PM
Last Post: newbieAuggie2019
  f-strings and termcolor newbieAuggie2019 5 568 Sep-22-2019, 03:52 AM
Last Post: newbieAuggie2019

Forum Jump:


Users browsing this thread: 1 Guest(s)