Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parse String
#1
I have a string as such:

<Role name: Data Editor_VDT, description: This type of account is meant for data editors, including mobile/field data collectors. This account cannot create content or groups, but can participate in groups, view VDOT content, and edit data shared with them.>

I want this out of it "Data Editor_VDT" ... Knowing that its will alway follow this format ... although the text after the 2nd Space and before the First Comma may change, and this is ok... as long as I capture it....

So that would be Starting after the Second Space and Ending at the First Comma.

Any thoughts?
Reply
#2
use slice see: https://docs.python.org/3/c-api/slice.html
Reply
#3
If the "Data Editor_VDT" value does not contain any special characters, you can easily extract it by splitting the string.

If it's not the right code, let me know and give me more examples of the texts so I can understand your requirements and modify the code.

text = '''<Role name: Data Editor_VDT, description: This type of account is meant for data editors, including mobile/field data collectors. This account cannot create content or groups, but can participate in groups, view VDOT content, and edit data shared with them.>'''

extract_text = text.split(', ')[0].split(': ')[-1]

print(extract_text) # Data Editor_VDT
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I parse the string? anna17 4 339 Apr-10-2024, 10:26 AM
Last Post: DeaD_EyE
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 205 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  [split] Parse Nested JSON String in Python mmm07 4 1,548 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,402 Apr-11-2021, 11:03 PM
Last Post: lastyle

Forum Jump:

User Panel Messages

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