Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extract text
#7
For varying text, you can use regular expressions
import re

lines = dropwhile(re.compile(r'(?!^\d+\s+yes\s*$)').match, file)
lines = takeuntil(equal('no\n'), lines)
sys.stdout.writelines(lines)
Output:
12 yes ok ok ok no
rektcol likes this post
Reply


Messages In This Thread
Extract text - by rektcol - Jun-27-2022, 07:53 AM
RE: Extract text - by DeaD_EyE - Jun-27-2022, 08:19 AM
RE: Extract text - by Gribouillis - Jun-27-2022, 08:48 AM
RE: Extract text - by ibreeden - Jun-27-2022, 11:21 AM
RE: Extract text - by Gribouillis - Jun-27-2022, 08:21 PM
RE: Extract text - by rektcol - Jun-28-2022, 07:38 AM
RE: Extract text - by Gribouillis - Jun-28-2022, 08:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extract text from PDF goryee 2 9,913 Jul-08-2024, 06:35 AM
Last Post: Pedroski55
  extract only text strip byte array Pir8Radio 7 7,605 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  Extract only certain text which are needed Calli 26 14,476 Oct-10-2022, 03:58 PM
Last Post: deanhystad
  Extract a string between 2 words from a text file OscarBoots 2 2,901 Nov-02-2021, 08:50 AM
Last Post: ibreeden
  Extract text based on postion and pattern guddu_12 2 2,582 Sep-27-2021, 08:32 PM
Last Post: guddu_12
  Extract specific sentences from text file Bubly 3 5,390 May-31-2021, 06:55 PM
Last Post: Larz60+
  extract color text from PDF Maha 0 2,715 May-31-2021, 04:05 PM
Last Post: Maha
Question How to extract multiple text from a string? chatguy 2 3,469 Feb-28-2021, 07:39 AM
Last Post: bowlofred
  How to extract a single word from a text file buttercup 7 7,794 Jul-22-2020, 04:45 AM
Last Post: bowlofred
  How to extract specific rows and columns from a text file with Python Farhan 0 4,266 Mar-25-2020, 09:18 PM
Last Post: Farhan

Forum Jump:

User Panel Messages

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