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()
#21
(May-19-2022, 10:05 PM)Pedroski55 Wrote: Ah well, I presumed you would only be receiving frequency data as Hertz from some CIA outpost in Alaska!
i am receiving from ham radio frequencies. :)

i am creating a function to handle the general case of a string with a number that float() (and int(s,10)) can convert followed by any unit the caller may use (as long as the unit can be distinguished from the number). one str argument. one 2-tuple return value. the return value will have either float or int followed by a str having the unit. int if the number has no given '.' character. if the number has '.' but its fractional part is all zero, it will still be type float. or i may decide to not convert the number and have 2 str in the returned tuple. if there is no number at all in the argument str, raise ValueError. if there is no unit at all, return a tuple with the number and an empty str. if the argument is not str or bytes, raise TypeError. if the argument is bytes, decode that to str and use str, remembering to encode all str results to bytes.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#22
(May-19-2022, 08:46 PM)Gribouillis Wrote: Here is a visual explanation of the regex
is there a tool to create that which i could use (Python 3.6,Ubuntu 18.04, Firefox 100)?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#23
(May-19-2022, 10:40 PM)Skaperen Wrote: is there a tool to create that which i could use (Python 3.6,Ubuntu 18.04, Firefox 100)?
I created the image by using a tool named jsyntrax. Unfortunately, it does not parse the regular expression, so I had to write my interpretation of the regular expression in a .spec file
indentstack(
    10,
    line(
        opt(choice('+', '-')),
        loop(None, ' '),
        choice(
            line(
                loop('0-9', None),
                opt(line('.', loop(None, '0-9')))),
            line('.', loop('0-9', None)))),
    opt(
        line(
            choice('e','E'),
            opt(choice('+', '-')),
            loop('0-9', None))))
jsyntrax runs on java. The only thing to do is to dowload the zip file, uncompress and run. There is also a Python syntrax module on pypi, but it seems abandoned by the author who switched to Java because of multiplatform concerns. I had an exception while trying to use Python's syntrax module. I don't want this module to die, I think I'm going to fork my own version.

It should not be too difficult to write a regex parser to convert a regular expression to such a diagram. I have already used Syntrax for a parsing project and it worked well. Perhaps I'll do it when I find some time to do so.
Reply
#24
Skaperen Wrote:it says at right side "giving back as needed". what does it mean by that? what is giving what to what? how is need determined? how can a regex disable that?
It's not easy if new to to Regex and try to understand something in a advance Regex as this.
It's about the use of ? look at Greedy and lazy quantifiers,then use languages as this expanding as needed (lazy) or giving back as needed
The regex for Python,the article is for JavaScript but it explanation really good,
and Regex pattern is universal with small changes how languages implementing it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Split pdf in pypdf based upon file regex standenman 1 2,096 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
  recall cool_person 1 1,039 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