-3

I read a c# code, I don't understand regex pattern.

string name = Regex.Replace(opts[2] ?? "", @"<<set:[A-Z]+>>", "");

What does @<<set:[A-Z]+>> mean?

Is there pattern using <<set: ?

I understand this sentence that if opts[2] is <<set:anithing>>something, name set something.
Is it correct?

naruke
  • 17
  • 2

1 Answers1

-1

You can find a detailed answer on sites where you can test regular expressions, like this one: https://regex101.com/r/9OWhtd/1

  • <<set: matches the characters <<set: literally (case sensitive)
  • Match a single character present in the list below [A-Z]
  • matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy) A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
  • Then >> matches the characters >> literally (case sensitive)

So it matches a string like <<set:ABC>> and replaces that with an empty string in your case.

Vivendi
  • 20,047
  • 25
  • 121
  • 196