question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regex path matching issue

See original GitHub issue

Hello,

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:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pimterrycommented, Jun 20, 2022

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 allow withQuery({ 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.

0reactions
chrisribecommented, Jun 17, 2022

I did find this showing all query param matchers do not support RegEx at all 😦

query-matching.spec.ts

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found