Search code examples
c#regexstring-comparison

C# - Straight-up answer for using Regex to compare strings?


I cannot understand the syntax at all! I feel like the stackoverflow community should get a simple solution to the problem I have (hopefully I'm not blind and have missed one of the thousands of regex questions here):

string myString = "$randomText$";
string myString2 = "$otherStuff$";

What would I use to check if any string has "$*$"? So as long as there's 2 $'s on the outside of the text?

Again, I'm sorry, and I Do understand there's other regex answers out there, but there's no way I'll ever understand it. I apologize, and have a good day.


Solution

  • You can do this by using this:

    string myString = "$randomText$";
    var match = Regex.Match(myString , @"\$.+\$");