我如何...使用Regex从字符串中提取变量名称 [英] How do I... Extract variable names from string with Regex

查看:73
本文介绍了我如何...使用Regex从字符串中提取变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我想用正则表达式读取给定字符串中的变量名。



例如,



嗨{$ name},你剩下{$ days}天。





字符串会显示给用户在文本框中,以便在给出执行命令后,他将知道将插入值的位置。如何使用正则表达式或任何其他方法从字符串中提取变量名称:(名称,天)?我正在用C#编程。



提前谢谢。

解决方案

name},你有{


days}天。





字符串在文本框中显示给用户,以便在给出执行命令后,他将知道值将被插入的位置。如何使用正则表达式或任何其他方法从字符串中提取变量名称:(名称,天)?我正在用C#编程。



提前致谢。


怎么样:(?' parm'\ {[^}] + \})

Hi everybody! I want to read variables names from a given string with regex.

For example,

Hi {$name}, you have {$days} days left.



The string is shown to user in a textbox so that he will know where values will be inserted after giving command for execution. How do I extract the variables names: (name, days) from the string using regex or any other method? I'm programming in C#.

Thanks in advance.

解决方案

name}, you have {


days} days left.



The string is shown to user in a textbox so that he will know where values will be inserted after giving command for execution. How do I extract the variables names: (name, days) from the string using regex or any other method? I'm programming in C#.

Thanks in advance.


How about : (?'parm'\{[^}]+\})


这篇关于我如何...使用Regex从字符串中提取变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆