Regex - global search

Hello!
How to capture all values?

 Regex: /\{\S+\}/g  // https://regexr.com

Playground

https://crates.io/crates/regex

The /g isn't regex syntax. That's syntax that some languages use to control the construction/mode of the regex itself.

I tried to make as few changes as possible: Rust Playground

Note that you aren't using capturing groups here, so there is no reason to use captures.

1 Like

@BurntSushi thx for your reply. :wink:

I have a new problem. I would like to replace a {key} for value.
Keys and values are stored in HashMap.

Playground

The second example here should help: Regex in regex - Rust

Here's an updated playground: Regex in regex - Rust

@BurntSushi Incorrect link?

Ah whoops, here it is, thank goodness the playground saves the last program I type. :sweat_smile:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cda1311ee516f2267c66db902e23aea8

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.