computationalmodelling / nbval

A py.test plugin to validate Jupyter notebooks
Other
438 stars 50 forks source link

Sanitize replace regex #206

Closed mloubout closed 3 months ago

mloubout commented 3 months ago

Is there a way to make the --nbval-sanitize-with to use regex for the replacement as well, i.e something like

[regex1]
regex: \w+\(\d+\)
replace: d

currently I can only make it hard-code "d" which will obviously fail too.

takluyver commented 3 months ago

The replacement uses re.sub(), so references like \1 should work.

currently I can only make it hard-code "d" which will obviously fail too.

Will it? The usual purpose for this sanitise mechanism is to replace things like timestamps with a fixed string such as TIMESTAMP.

mloubout commented 3 months ago

I found a better way to fix my issue so it's fine, sorry for that.