Replace non-alphanumeric characters from string

For the navigation on my website, I created an index that is built from headline blocks. When you click on a headline in the index you scroll to that part in the page. One problem is that some headlines have non-alphanumeric content (like (, / or ?) that i don’t want to end up in the URL, and that I’d like to replace with a ‘_’

I understood that a regular expressions like '/[^a-z0-9 ]/i' should work normally. But when I add this to Str::replace() it does not replace any alphanumeric character (it does not react nor give an error)
Does Kirby need specific/different symbols to work? Or is there maybe another helper in Kirby that replaces non-alphanumeric characters?

<ul class="index">
 <?php foreach ($page->process()->toBlocks() as $block): ?>
  <?php if ($block->type() == "heading"): ?>
    <a href="#<?= Str::replace($block->excerpt(), '/[^a-z0-9 ]/i', '_' ) ?>"><?= $block->excerpt() ?></a>
  <?php endif ?>
 <?php endforeach ?>

I think, the Str::replace function from Kirby toolkit searches for a string (or array of strings), not for a regular expression. Use PHP function preg_replace if there is no equivalent in the toolkit.

Or, use the Str::slug function from the toolkit.

Thank you, helped like a charm! Went for preg_replace to solve it.
This is my first project learning both Kirby and PHP via that route, so wasn’t even aware I could combine it with Kirby’s language like that.