Title: function /(?
Open Graph Title: function /(?
X Title: function /(?
Description: Wouldn't it be cool if this or something similar would be possible... # https://regex101.com/r/EpiXHF/2 [regex]$regEx = @" (?mx-i) ^ (?
Open Graph Description: Wouldn't it be cool if this or something similar would be possible... # https://regex101.com/r/EpiXHF/2 [regex]$regEx = @" (?mx-i) ^ (?
X Description: Wouldn't it be cool if this or something similar would be possible... # https://regex101.com/r/EpiXHF/2 [regex]$regEx = @" (?mx-i) ^ (?<amount>\d+) (?<unit> (?: [s] (?:econd )?...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/10042
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"function /(?\u003cval>\\d+)(?\u003ctimeUnit>)/([int]$val, [string]$timeUnit) { ... }","articleBody":"Wouldn't it be cool if this or something similar would be possible...\r\n```\r\n# https://regex101.com/r/EpiXHF/2\r\n[regex]$regEx = @\"\r\n(?mx-i)\r\n^\r\n (?\u003camount>\\d+)\r\n (?\u003cunit>\r\n (?: [s] (?:econd )? ) |\r\n (?: (?:Second ) ) |\r\n (?: [M] (?:inute )? ) |\r\n (?: (?:minute ) ) |\r\n (?: [h] (?:our )? ) |\r\n (?: (?:Hour ) ) |\r\n (?: [Dd] (?:ay )? ) |\r\n (?: [Ww] (?:eek )? ) |\r\n (?: [m] (?:onth )? ) |\r\n (?: (?:Month ) ) |\r\n (?: [Yy] (?:ear )? )\r\n )(?:(?\u003c=[\\D]{3})[s])?\r\n (?\u003cdirection> [Aa]go)\r\n$\r\n\"@\r\n\r\n\r\nfunction $regEx([int]$amount, [string]$unit, [string]$direction)\r\n{\r\n if($direction.ToLower() -eq \"ago\")\r\n {\r\n $amount = $amount*-1;\r\n }\r\n else\r\n {\r\n throw \"Unsupported direction: $direction\";\r\n }\r\n\r\n [DateTime]$now = Get-Date;\r\n [DateTime]$result;\r\n switch -Regex ($unit)\r\n {\r\n \"(?x-i) s | (?i) second\" {$result = $now.AddSeconds($amount);}\r\n \"(?xi) M | (?i) minute\" {$result = $now.AddMinutess($amount);}\r\n \"(?x-i) h | (?i) hour\" {$result = $now.AddHours($amount);}\r\n \"(?xi) d | (?i) days\" {$result = $now.AddDays($amount);}\r\n \"(?xi) w | (?i) week\" {$result = $now.AddDays($amount*7);}\r\n \"(?x-i) m | (?i) month\" {$result = $now.AddMonths($amount);}\r\n \"(?xi) y | (?i) year\" {$result = $now.AddYears($amount);}\r\n Default {throw \"Unsupported unit: $unit\"}\r\n }\r\n\r\n return $result;\r\n}\r\n\r\n\r\n```\r\n### Proposed technical implementation details (optional)\r\nPerhaps something along this way...\r\n1. Give the function a unique internal name just to keep track of it\r\n2. As a last step, when no other function, cmdLet, application or whatever is found, then use the regEx on the potential command and see if it match.\r\n3. If it match...\r\n 1. make a temporary copy of the function from step 1 (or assign it an alternative name or something)\r\n 2. Name the temporary copy in such a way that it would have ben executed if it had existed as a \"normal function\"\r\n 3. Call this new temporary function, with the named capture groups from the regex as it's input parameters\r\n4. cleanup and remove all temporary stuff\r\n\r\n\r\n\u003c!-- \r\nA clear and concise description of what you want to happen.\r\nConsider providing an example PowerShell experience with expected result.\r\n-->\r\n","author":{"url":"https://github.com/Bartolomeus-649","@type":"Person","name":"Bartolomeus-649"},"datePublished":"2019-07-01T18:06:33Z","url":"https://github.com/PowerShell/PowerShell/issues/10042"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:0cef9a4d-4038-c02b-1095-42ef74ec6100 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E4D2:18B2E:13E964:1B099D:6AFD4CB3 |
| html-safe-nonce | c68b6a172e33c7e0f1583fd37be144d458bb87e15dbd4cea08c50f1e599aeeb3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEQyOjE4QjJFOjEzRTk2NDoxQjA5OUQ6NkFGRDRDQjMiLCJ2aXNpdG9yX2lkIjoiNTg0MzA5MzAyNzA1MTg4MzY5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4402bb9dea9ea619a690f9b21eb6fbefcae4b27b58e2f686a478636bdb66fe91 |
| hovercard-subject-tag | issue:462841741 |
| 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/PowerShell/PowerShell/10042/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9d15eef553aa6ce810c21b2be85e3203d5bf1cb431d4aaca327318aa8427a20f/PowerShell/PowerShell/issues/10042 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9d15eef553aa6ce810c21b2be85e3203d5bf1cb431d4aaca327318aa8427a20f/PowerShell/PowerShell/issues/10042 |
| og:image:alt | Wouldn't it be cool if this or something similar would be possible... # https://regex101.com/r/EpiXHF/2 [regex]$regEx = @" (?mx-i) ^ (? |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Bartolomeus-649 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| 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 | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width