Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #197871
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Veek M <veekjunk@foobar.com> |
| Newsgroups | comp.lang.python |
| Subject | re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') how does it work? |
| Date | Sun, 9 Aug 2026 00:21:48 -0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 19 |
| Message-ID | <1158h6s$1ts3e$1@dont-email.me> (permalink) |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Sun, 09 Aug 2026 00:21:49 +0000 (UTC) |
| Injection-Info | dont-email.me; logging-data="2027630"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6WM7OacmHnKStbSMR5Zt+"; posting-host="d80449bd368bcccdf40149aea5bd0cee" |
| User-Agent | Pan/0.154 (Izium; 517acf4) |
| Cancel-Lock | sha1:wqCAYWaaWVOw2ZnlJyaE5BCZAMo= sha256:0xy6f58uSB9PiI4eXH2vFxFgBP+2qhD0StyNY2Rn8/A= sha1:dwROua5btukVWnDLZiSse0rjyMg= sha256:KLDNP5/IWamqjkz169K48oEiSfFvhrU+ml4AIQR/x2w= |
| Xref | csiph.com comp.lang.python:197871 |
Show key headers only | View raw
look-ahead look-behind don't consume string so how does it advance through the string - could someone clearly explain how it works. re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') 'NA,1,NA,NA,two,3,NA,NA,NA' re.sub(r'(?<![^,])(?![^,])', 'NA', ',1,,,two,3,,,') 'NA,1,NA,NA,two,3,NA,NA,NA' My understanding is that there has to be a pattern that consumes the string eg: here [^,] consumes two 3 four and 5 but the look-ahead look- behind eliminate 5 re.findall(r'(?<=,)[^,]+(?=,)', '1,two,3,four,5') ['two', '3', 'four'] If it's matching the empty string '' then why don't we get NA,NA1 etc for ,1
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') how does it work? Veek M <veekjunk@foobar.com> - 2026-08-09 00:21 +0000
Re: re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') how does it work? Jon Ribbens <jon+usenet@unequivocal.eu> - 2026-08-09 01:26 +0000
Re: re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') how does it work? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-08-09 11:24 +0000
Re: re.sub(r'((?<=\A)|(?<=,))(?=,|\Z)', 'NA', ',1,,,two,3,,,') how does it work? Veek M <veekjunk@foobar.com> - 2026-08-11 09:21 +0000
csiph-web