Re: Ask for help on using re
Neil 在 2021年8月5日 星期四下午6:36:58 [UTC+8] 的信中寫道:
> Jach Feng wrote:
> > I want to distinguish between numbers with/without a dot attached:
> >
> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
> re.compile(r'ch \d{1,}[.]').findall(text)
> > ['ch 1.', 'ch 23.']
> re.compile(r'ch \d{1,}[^.]').findall(text)
> > ['ch 23', 'ch 4 ', 'ch 56 ']
> >
> > I can guess why the 'ch 23' appears in the second list. But how to get rid
> > of it?
> >
> > --Jach
> Does
>
> >>> re.findall(r'ch\s+\d+(?![.\d])',text)
>
> do what you want? This matches "ch", then any nonzero number of
> whitespaces, then any nonzero number of digits, provided this is not
> followed by a dot or another digit.
Yes, the result is what I want. Thank you, Neil!
The solution is more complex than I expect. Have to digest it:-)
--Jach
--
https://mail.python.org/mailman/listinfo/python-list
Ask for help on using re
I want to distinguish between numbers with/without a dot attached:
>>> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
>>> re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', 'ch 23.']
>>> re.compile(r'ch \d{1,}[^.]').findall(text)
['ch 23', 'ch 4 ', 'ch 56 ']
I can guess why the 'ch 23' appears in the second list. But how to get rid of
it?
--Jach
--
https://mail.python.org/mailman/listinfo/python-list
error from pypa build
I'm building a pure python wheel in a python3.9 virtualenv. If I use python setup.py bdist_wheel I do get a wheel named rlextra-3.6.0-py3-none-any.whl I'm trying out building a modern python 3 only wheel so I followed instructions here https://packaging.python.org/tutorials/packaging-projects/#creating-the-package-files and see the error below which is not very informative. Any ideas of what's wrong? I still get the error even after upgrading pip so I don't think that is the problem. > (.py39) user@pc:~/devel/reportlab/REPOS/rlextra > $ pip install build > Collecting build > Downloading build-0.5.1-py2.py3-none-any.whl (15 kB) > Collecting pep517>=0.9.1 > .. > Installing collected packages: tomli, pyparsing, toml, pep517, packaging, build > Successfully installed build-0.5.1 packaging-21.0 pep517-0.11.0 pyparsing-2.4.7 toml-0.10.2 tomli-1.2.0 > WARNING: You are using pip version 21.1.3; however, version 21.2.2 is available. > You should consider upgrading via the '/home/user/devel/reportlab/.py39/bin/python39 -m pip install --upgrade pip' command. > (.py39) user@pc:~/devel/reportlab/REPOS/rlextra > $ ls > build dist docs examples LICENSE.txt README.txt setup.cfg setup.py src tests tmp > (.py39) user@pc:~/devel/reportlab/REPOS/rlextra > $ python -m build --wheel > Traceback (most recent call last): > File "/home/user/devel/reportlab/.py39/lib/python3.9/site-packages/build/__main__.py", line 302, in main > build_call(args.srcdir, outdir, distributions, config_settings, not args.no_isolation, args.skip_dependency_check) > File "/home/user/devel/reportlab/.py39/lib/python3.9/site-packages/build/__main__.py", line 145, in build_package > _build(isolation, builder, outdir, distribution, config_settings, skip_dependency_check) > File "/home/user/devel/reportlab/.py39/lib/python3.9/site-packages/build/__main__.py", line 101, in _build > return _build_in_isolated_env(builder, outdir, distribution, config_settings) > File "/home/user/devel/reportlab/.py39/lib/python3.9/site-packages/build/__main__.py", line 77, in _build_in_isolated_env > with IsolatedEnvBuilder() as env: > File "/home/user/devel/reportlab/.py39/lib/python3.9/site-packages/build/env.py", line 92, in __enter__ > executable, scripts_dir = _create_isolated_env_venv(self._path) > File "/home/user/devel/reportlab/.py39/lib/python3.9/site-packages/build/env.py", line 221, in _create_isolated_env_venv > pip_distribution = next(iter(metadata.distributions(name='pip', path=[purelib]))) > StopIteration > > ERROR > (.py39) user@pc:~/devel/reportlab/REPOS/rlextra thanks for any assistance -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: Ask for help on using re
Jach Feng wrote:
> I want to distinguish between numbers with/without a dot attached:
>
text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
re.compile(r'ch \d{1,}[.]').findall(text)
> ['ch 1.', 'ch 23.']
re.compile(r'ch \d{1,}[^.]').findall(text)
> ['ch 23', 'ch 4 ', 'ch 56 ']
>
> I can guess why the 'ch 23' appears in the second list. But how to get rid of
> it?
>
> --Jach
Does
>>> re.findall(r'ch\s+\d+(?![.\d])',text)
do what you want? This matches "ch", then any nonzero number of
whitespaces, then any nonzero number of digits, provided this is not
followed by a dot or another digit.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Ask for help on using re
On Thu, 5 Aug 2021 02:40:30 -0700 (PDT), Jach Feng wrote:
I want to distinguish between numbers with/without a dot attached:
>>> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
>>> re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', 'ch 23.']
>>> re.compile(r'ch \d{1,}[^.]').findall(text)
['ch 23', 'ch 4 ', 'ch 56 ']
I can guess why the 'ch 23' appears in the second list. But how to get
rid of it?
>>> re.findall(r'ch \d+[^.0-9]', "ch 1. is ch 23. is ch 4 is ch 56 is ")
['ch 4 ', 'ch 56 ']
--
To email me, substitute nowhere->runbox, invalid->com.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Ask for help on using re
Le 05/08/2021 à 11:40, Jach Feng a écrit :
I want to distinguish between numbers with/without a dot attached:
text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', 'ch 23.']
re.compile(r'ch \d{1,}[^.]').findall(text)
['ch 23', 'ch 4 ', 'ch 56 ']
I can guess why the 'ch 23' appears in the second list. But how to get rid of
it?
--Jach
>>> import re
>>> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
>>> re.findall(r'ch \d+\.', text)
['ch 1.', 'ch 23.']
>>> re.findall(r'ch \d+(?!\.)', text) # (?!\.) for negated look ahead
['ch 2', 'ch 4', 'ch 56']
--
https://mail.python.org/mailman/listinfo/python-list
Re: Ask for help on using re
Le 05/08/2021 à 17:11, ast a écrit :
Le 05/08/2021 à 11:40, Jach Feng a écrit :
I want to distinguish between numbers with/without a dot attached:
text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', 'ch 23.']
re.compile(r'ch \d{1,}[^.]').findall(text)
['ch 23', 'ch 4 ', 'ch 56 ']
I can guess why the 'ch 23' appears in the second list. But how to get
rid of it?
--Jach
>>> import re
>>> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
>>> re.findall(r'ch \d+\.', text)
['ch 1.', 'ch 23.']
>>> re.findall(r'ch \d+(?!\.)', text) # (?!\.) for negated look ahead
['ch 2', 'ch 4', 'ch 56']
import regex
# regex is more powerful that re
>>> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
>>> regex.findall(r'ch \d++(?!\.)', text)
['ch 4', 'ch 56']
## ++ means "possessive", no backtrack is allowed
--
https://mail.python.org/mailman/listinfo/python-list
Re: Ask for help on using re
Le 05/08/2021 à 17:11, ast a écrit :
Le 05/08/2021 à 11:40, Jach Feng a écrit :
I want to distinguish between numbers with/without a dot attached:
text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', 'ch 23.']
re.compile(r'ch \d{1,}[^.]').findall(text)
['ch 23', 'ch 4 ', 'ch 56 ']
I can guess why the 'ch 23' appears in the second list. But how to get
rid of it?
--Jach
>>> import re
>>> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
>>> re.findall(r'ch \d+\.', text)
['ch 1.', 'ch 23.']
>>> re.findall(r'ch \d+(?!\.)', text) # (?!\.) for negated look ahead
['ch 2', 'ch 4', 'ch 56']
ops ch2 is found. Wrong
--
https://mail.python.org/mailman/listinfo/python-list
