Python Forum
Finding multiple strings between the two same strings
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)
Reply


Messages In This Thread
Finding multiple strings between the two same strings - by Slither - Jun-05-2019, 08:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Pad strings to always get three-digit number? Winfried 2 282 Jan-27-2024, 05:23 PM
Last Post: Winfried
  Tab Delimited Strings? johnywhy 7 485 Jan-13-2024, 10:34 PM
Last Post: sgrey
Question [PyMuPDF] Grab all strings of a given size? Winfried 3 599 Dec-26-2023, 07:39 AM
Last Post: Pedroski55
  How to read module/class from list of strings? popular_dog 1 422 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  Hard time trying to figure out the difference between two strings carecavoador 2 644 Aug-16-2023, 04:53 PM
Last Post: carecavoador
  Trying to understand strings and lists of strings Konstantin23 2 696 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  problem in using int() with a list of strings akbarza 4 647 Jul-19-2023, 06:46 PM
Last Post: deanhystad
  Taking Mathematical Expressions from Strings quest 2 664 Jul-02-2023, 01:38 PM
Last Post: Pedroski55
  xml indent SubElements (wrapping) with multiple strings ctrldan 2 1,382 Jun-09-2023, 08:42 PM
Last Post: ctrldan
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020