(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.
(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)?
(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.
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.