Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Regex
#1
I have the following text file:
Output:
S = 0, X are: (1, 0, 1, 1, 0, 0, )S = 0, Z are: (0, 1, 1, 1, 0, 1, )Data bits measurement:0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, Measured l0: 1, Measured l1: 0 S = 0, X are: (1, 1, 0, 0, 0, 1, )S = 0, Z are: (1, 1, 0, 0, 1, 1, )Data bits measurement:1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, Measured l0: 0, Measured l1: 1 S = 0, X are: (1, 1, 0, 0, 1, 1, )S = 0, Z are: (1, 1, 0, 0, 1, 1, )Data bits measurement:1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, Measured l0: 1, Measured l1: 0 S = 0, X are: (1, 1, 1, 0, 1, 1, )S = 0, Z are: (0, 0, 0, 1, 0, 0, )Data bits measurement:0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, Measured l0: 1, Measured l1: 0 S= 0, X are: (1, 1, 0, 1, 1, 0, )S = 0, Z are: (0, 0, 0, 1, 0, 0, )Data bits measurement:0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, Measured l0: 1, Measured l1: 0 S = 0, X are: (1, 1, 0, 0, 1, 1, )S = 0, Z are: (1, 1, 1, 0, 0, 1, )Data bits measurement:1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, Measured l0: 1, Measured l1: 0
Now, I want to count how many same Z value I have and I have many l0 I have for this Z value:
For example:
Output:
011101 - 1 and l0 1 (in total) 110011 - 2 and l0 1 (in total) 000100 - 2 and l0 2 (in total) 111001 - 1 and l0 1 (in total)
I thought regex can be nice but I could not manage to use it:
Here is my code:
with open("f.dat") as file:
    lines = file.readlines()
    #Z=re.search("(^Z*)",line)
    for i in re.findall(r'Z are: (=(\d+)&',lines):
           print(i)
And I got this error:
Error:
raise source.error("missing ), unterminated subpattern", re.error: missing ), unterminated subpattern at position 17
Reply


Messages In This Thread
Python Regex - by quest - Sep-21-2022, 12:16 PM
RE: Python Regex - by deanhystad - Sep-21-2022, 08:13 PM
RE: Python Regex - by quest - Sep-22-2022, 03:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python regex: get rid of double dot wardancer84 4 2,462 Sep-09-2021, 03:03 PM
Last Post: wardancer84
  Using Regex Expression With Isin in Python eddywinch82 0 2,356 Apr-04-2021, 06:25 PM
Last Post: eddywinch82
  Exception handling in regex using python ShruthiLS 1 2,421 May-04-2020, 08:12 AM
Last Post: anbu23
  Python the regex not getting any attributes sarath_unrelax 1 1,906 Dec-19-2019, 11:06 AM
Last Post: Larz60+
  Python regex to get only numbers tantony 6 4,254 Oct-09-2019, 11:53 PM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

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