How to specify regex replacement for different capture groups in F #

I am writing the md2html compiler in F # and I want to replace the surrounding texts **with <b>and tags </b>.

eg. this is **bold**will be changed tothis is <b>bold</b>

I am trying to accomplish this using a method Regex.Replaceusing a template (\*\*).*?(\*\*). Thus, the first capture group will be replaced by <b>, and the second will be replaced by </b>. I would like to know how can I specify a replacement for these different “capture groups”, and not for all regex matching?

+4
source share
3 answers

, . , .

\*\*(.*?)\*\* <b>$1</b>.

, Singleline (?s): (?s)\*\*(.*?)\*\*

+4

: \*\*(.*?)\*\* <b>$1</b>

:

  • \*\* **.
  • ( .
  • .* , , .
  • ? .* , .
  • ) .
  • \*\* **.
+4

- **, .

Regex.Replace("this is **bold**", "\*\*(.*?)\*\*", "<b>$1</b>")

Regex.Replace , .

+3

Source: https://habr.com/ru/post/1678465/


All Articles