Python Forum
trying to recall a regex for re.split()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to recall a regex for re.split()
#19
Ah well, I presumed you would only be receiving frequency data as Hertz from some CIA outpost in Alaska!

Maybe the spooks are also sending recipe data to their mothers. oz, lbs

measurements = ['2.5hz','2.5Hz', '2.5mHz', '2.5GHz', '2.5THz', '2.5mTHz', '2.5', 'h', 'HZ', 'Hz' ]
my_pattern = re.compile("[a-z, A-Z]")
for m in measurements:    
    # if there is no text
    try:
        start_pos = my_pattern.search(m).span()[0]
        print('measured frequency is', m)
        start_pos = my_pattern.search(m).span()[0]
        print('number =', m[:start_pos], 'units =', m[start_pos:])
    except AttributeError:    
        continue
Reply


Messages In This Thread
RE: trying to recall a regex for re.split() - by Pedroski55 - May-19-2022, 10:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split pdf in pypdf based upon file regex standenman 1 2,197 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
  recall cool_person 1 1,082 May-07-2022, 08:04 AM
Last Post: menator01

Forum Jump:

User Panel Messages

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