Python Forum
Identifying keywords in text
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Identifying keywords in text
#6
Example of using re

import re

mystring = 'Peter Piper peppers picked a peck of pickled peppers. Where\'s peppers the peck of dozens of pickled peppers Peter Piper picked?'

findit = re.search(r'peck(.*?)peppers', mystring).group(1)

print(f'One occurance  -> {findit}')

findit = re.findall(r'(?:peck)(.*?)(?:peppers)', mystring)

print(f'Multiple occurances - > {findit}')
Output:
One occurance -> of pickled Multiple occurances - > [' of pickled ', ' of dozens of pickled ']
snippsat likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply


Messages In This Thread
Identifying keywords in text - by drchips - Mar-28-2022, 07:21 PM
RE: Identifying keywords in text - by menator01 - Mar-28-2022, 07:31 PM
RE: Identifying keywords in text - by Pedroski55 - Mar-29-2022, 01:22 AM
RE: Identifying keywords in text - by drchips - Mar-29-2022, 08:12 AM
RE: Identifying keywords in text - by Pedroski55 - Mar-29-2022, 09:10 AM
RE: Identifying keywords in text - by menator01 - Mar-29-2022, 09:12 AM
RE: Identifying keywords in text - by snippsat - Mar-29-2022, 12:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Identifying Valid and Invalid Phone Contact KiranKandavalli 3 496 Apr-03-2025, 07:12 PM
Last Post: deanhystad
  Identifying if the program I have is python and then decompiling jpnyc 7 3,940 Jun-02-2022, 10:16 PM
Last Post: jpnyc
  trying to put a a filter on identifying a straight CompleteNewb 1 2,190 Dec-01-2021, 11:11 PM
Last Post: CompleteNewb
  Customize Python Keywords for IDLE alanvers 0 2,485 Apr-03-2021, 10:56 AM
Last Post: alanvers
  could someone explain keywords, marks, and function DrKatherineThuyMiller 14 6,594 Jul-23-2020, 07:14 PM
Last Post: DrKatherineThuyMiller
  Identifying string success flag graham23s 4 4,524 Aug-14-2019, 09:27 PM
Last Post: graham23s
  identifying a dictionary with an attribute? Skaperen 7 5,149 Oct-04-2018, 05:48 AM
Last Post: Skaperen
  Can I search from Python, automatically and randomly generated keywords in Google? xX_Prophit_Xx 0 2,848 Sep-07-2018, 04:43 PM
Last Post: xX_Prophit_Xx
  Identifying only specific words in a string GilbyScarChest 2 3,399 Aug-08-2018, 03:22 AM
Last Post: GilbyScarChest
  Identifying the value of all adjacent elements in an array JoeB 2 9,669 Nov-23-2017, 05:10 PM
Last Post: JoeB

Forum Jump:

User Panel Messages

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