Title: Improve speed of stdlib functions by replacing `re` uses · Issue #130167 · python/cpython · GitHub
Open Graph Title: Improve speed of stdlib functions by replacing `re` uses · Issue #130167 · python/cpython
X Title: Improve speed of stdlib functions by replacing `re` uses · Issue #130167 · python/cpython
Description: We can often find the module re in the standard library modules but it can be replaced (if it is possible). I don't suggest removing it everywhere, there are places where its use is appropriate, but there are also places where it is an u...
Open Graph Description: We can often find the module re in the standard library modules but it can be replaced (if it is possible). I don't suggest removing it everywhere, there are places where its use is appropriate, bu...
X Description: We can often find the module re in the standard library modules but it can be replaced (if it is possible). I don't suggest removing it everywhere, there are places where its use is appropriate...
Opengraph URL: https://github.com/python/cpython/issues/130167
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve speed of stdlib functions by replacing `re` uses","articleBody":"We can often find the module `re` in the standard library modules but it can be replaced (if it is possible). I don't suggest removing it everywhere, there are places where its use is appropriate, but there are also places where it is an unnecessary solution and leads to unpleasant consequences (they can be found below)\n\n**Cons** of regular expressions and reasons to replace regular expressions with functions and methods:\n1. We spend time to compile re pattern (one time, but anyway we spend it)\n2. In most cases simple string methods are faster (according to my benchmarks about 2x)\n3. We can remove `import re` which will affect import time\n4. *Additionally*: I think for those who don't know regular expressions, the code is more difficult to read and therefore difficult to maintain.\n\n\u003e [!IMPORTANT]\n\u003e For those who want to work on the issue, please:\n\u003e\n\u003e - Read https://devguide.python.org/getting-started/pull-request-lifecycle/ before anything else.\n\u003e - Select **one** function to improve. It's easier to review and possibly backport.\n\u003e - Always report benchmarks using `pyperf`, `hyperfine`, and `tuna` together with `-X importtime` to compare import times and execution time. \n\u003e - Open a pull request with the following title: \u003ccode\u003egh-130167: Improve speed of \\`module.function\\` by replacing \\`re\\`\u003c/code\u003e\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-130170\n* gh-130242\n* gh-130243\n* gh-131919\n* gh-131925\n* gh-131924\n* gh-132065\n* gh-132666\n* gh-143292\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/donbarbos","@type":"Person","name":"donbarbos"},"datePublished":"2025-02-16T01:48:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/130167/cpython/issues/130167"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:50dbab4f-a60b-e1c7-4d74-ccebfacc9c0b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBEE:1531FB:B94241:104F907:696A60FF |
| html-safe-nonce | ac30f629413dd8f857a1118719bee2e4310bdc0c464acc0df5a57a6cebe32399 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkVFOjE1MzFGQjpCOTQyNDE6MTA0RjkwNzo2OTZBNjBGRiIsInZpc2l0b3JfaWQiOiI4MDg1OTczNjE0MjY2ODAzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5375c9fa7ba1bc872bb9c47d3df73590b3de1707b45e57560c168337e5fd2ea9 |
| hovercard-subject-tag | issue:2855818065 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/130167/issue_layout |
| twitter:image | https://opengraph.githubassets.com/02ffebcc3055511dd2b1026cfdfb2439d09f9b815b13a5b0dd342b4f6d4ab156/python/cpython/issues/130167 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/02ffebcc3055511dd2b1026cfdfb2439d09f9b815b13a5b0dd342b4f6d4ab156/python/cpython/issues/130167 |
| og:image:alt | We can often find the module re in the standard library modules but it can be replaced (if it is possible). I don't suggest removing it everywhere, there are places where its use is appropriate, bu... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | donbarbos |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9b7735a184970dd9333b2cbe036c8f3c0a9108c64aaa93827c5a64fc70993392 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 87cbd411c2982752221b5751d583a515b23bf5fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width