Comments (5)
Hi @jacobbednarz! I would do it with a rewrite rule.
You can add this to the command line invocation with
-rule 'where rewrite :[topic] { :[x]s -> :[x] }'
Basically, this rule fires and rewrites topic
if :[x]s
matches and leaves it untouched otherwise.
Docs for this: https://comby.dev/docs/advanced-usage#rewrite-expressions
I thought about and tried regex with lookahead (comby supports perl regex in that syntax) and things like boundary assertions (but those don't seem to pan out and probably misleading / tricky behavior to reason about)
from comby.
ah thank you! I didn't even click that a rule could be applicable here. appreciate it!
from comby.
sorry for reusing this issue but i've got some behaviour here that i'm not sure about - https://bit.ly/3vGPy9f.
my expectation is that /zones/{foo}/rulesets/phases/{bar}/entrypoint/versions/{baz}
becomes /zones/{zone_id}/rulesets/phases/{phase_id}/entrypoint/versions/{version_id}
however, for some reason, the "s" in the middle of these words is being targeted. am i holding this wrong? or is there a different syntax i should be using here instead?
from comby.
hey @jacobbednarz, good question, it seems I simplified this in my head too early 😄
I'll give a workaround before the longer explanation. It is a bit trickier to grok but I think it works in the general case:
Basically, we make the /
of the path part of the match, and then we can use that context to chop off an s
before /
(and not just any s
, which is what was happening before). Note the changes to the rule and the output pattern.
Strictly speaking you only need to match the trailing /
so this also works:
Long explanation,
What was happening before is that, the way comby matches something like :[x]s
is "match as much as possible until you see the thing after it (in this case s
)". So when it matches against phases
, it matches up to pha
, sees an s
after it, and stops. so we end up with two :[x]s -> :[x]
happening twice for phases
-> [pha][e]
. But what we really want is only the last s
. How do we know what is "last"? It turns out it's difficult to use regex or comby to say what is "last", and we don't have a "chop suffix" function or something like that yet. But based on your pattern, we know that a /
means the s before it is "last", so we are using that fact to chop the suffix. Hope that helps
from comby.
ah, that makes perfect sense! thanks again 🥇
from comby.
Related Issues (20)
- builds for arm64 HOT 2
- Only first match is located HOT 1
- Keep getting Exception: (Sys_error "xxxx.swift: Read-only file system
- A match expression followed by a rewrite expression using a named whitespace matcher produces unexpected output
- Difficulties connecting to comby.dev HOT 4
- Support glibc 2.28 HOT 1
- Comby support for OCaml? HOT 3
- Comby Image not supporting configuration files(.TOML) HOT 1
- [non-issue] What's Omega matcher engine? HOT 1
- Unicode character in match template appears to break matching/behaves as wildcard HOT 1
- Case of comby not being compatible with .csproj-file
- Comby doesn't work correctly with a single quote in html HOT 1
- Typescript/Javascript expressions embedded in template strings not recognized
- comby.live is missing version information HOT 2
- A
- A
- Allow specification of `matcher` for patterns in TOML config file HOT 1
- The get-comby.netlify.app script installs an old version of Comby HOT 1
- C language is including ';' in expression syntax HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comby.