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
  Mutable Strings millpond 3 135 Aug-24-2020, 08:42 AM
Last Post: millpond
  printing strings with format leodavinci1990 1 242 Aug-21-2020, 02:00 AM
Last Post: micseydel
  Read strings and numbers in columns from a file suvadip 4 401 Aug-11-2020, 09:37 PM
Last Post: suvadip
  f-strings and termcolor newbieAuggie2019 6 2,038 Jul-28-2020, 02:50 AM
Last Post: santarosajoe
  Skipping Strings Kristenl2784 0 344 Jul-27-2020, 06:01 PM
Last Post: Kristenl2784
  Introduction to escaping characters in strings Geelong_crazy 1 171 Jul-18-2020, 06:58 PM
Last Post: DT2000
  How to give space when concaneting strings deshanish 1 204 Jul-15-2020, 03:08 AM
Last Post: bowlofred
  Comparing Values/QC Within Two Strings uttadms31 2 364 Jul-07-2020, 03:49 PM
Last Post: uttadms31
  How to merge strings through graphs Den 6 550 Jun-29-2020, 07:07 AM
Last Post: Den
  get method not counting number of strings in dictionary LearningTocode 2 246 Jun-13-2020, 11:17 PM
Last Post: LearningTocode

Forum Jump:


Users browsing this thread: 1 Guest(s)