Regex path matching issue
See original GitHub issueHello,
I was looking at allowing different RegEx patterns in the url matching. RegEx test cases
I see in the test cases you only run tests with direct regex expressions and not strings.
await server.get(/.*.txt/).thenReply(200, 'Fake file');
Tried to create a regex pattern via new RegExp(“some regex pattern string”) but I am having match issues.
const regExPattern = new RegExp(regExPatternString, 'g');
await server.get(regExPattern).thenReply(200, 'Fake file');
Any tips ?
_Originally posted by @chrisribe in https://github.com/httptoolkit/mockttp/issues/9#issuecomment-1158910337_
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Regex for parsing directory and filename
I'm trying to write a regex that will parse out the directory and filename of a fully qualified path using matching groups.
Read more >Issue with request path match with regex #6725
We are having issue with Route matching. There are two routes configured under different services having paths with regex, where the request ...
Read more >path-to-regexp
path -to-regexp. TypeScript icon, indicating that this package has built-in type declarations. 6.2.1 • Public • Published 8 months ago.
Read more >regex matching page paths?
Unfortunately I can't handle the regex – I want to exclude the following pages and paths. /login/ /contact/ /client-section/*. Maybe someone can give...
Read more >Regex Match issue - Studio
I have a problem. I need to find all the numbers which comes after the Voucher. I am using (?<!Voucher)\d+ but its selecting...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, it’s not possible to do query matching by regex right now. PRs very welcome though! It should be fairly easy to add a
withQueryMatching(/regex/)
matcher that would do what you want.Alternatively, it might make sense to extend
withQuery({ v: '1.0.0' })
to allowwithQuery({ v: /1.0.[0-9]/ })
, so you can provide regexes to match against individual query values, independent of the order.If you’re interested in adding that, I’d suggest starting by writing a couple of tests for it, then exploring the existing matcher definition implementations you can find defined around here: https://github.com/httptoolkit/mockttp/blob/0d586c5336a659f788a6d65b4bf6d979b3cc29ae/src/rules/base-rule-builder.ts#L136-L144.
I did find this showing all query param matchers do not support RegEx at all 😦
query-matching.spec.ts