I have a Expression ($ASMLNA$ * $TSM$ * 8 * ($GrossDownTarget$ * $005930K$)+15)
Now I am trying to get all the variables which is between $ $. Example $ASMLNA$ so for me it should give ASMLNA.
I have tried using RegEx and this is what I have been able to do till now
Regex r = new Regex(@"[^\$]"); string Contents = txtRegEx.Text.Trim(); MatchCollection ImageCollection = r.Matches(Contents); string tempContents = string.Empty; foreach (Match match in ImageCollection) { tempContents+= match.Value; }
It will be开发者_StackOverflow中文版 great if someone can point me in correct direction.
Try this regex:
(?<=\$)\b[^$]+\b(?=\$)
If your variables can only contain word chars ([a-zA-Z0-9_]
), this regex would be better:
(?<=\$)\w+(?=\$)
Your expression only matches a $ at the beginning of the string. To get groups, I think you want something like this: @"(\$.+?\$)"
Edit: Oops. I missed the bit about stripping out the $. Try this version instead: \$(.+?)\$
精彩评论