正则表达式在花括号之间获取字符串“{我想要花括号之间的内容}” [英] Regex to get string between curly braces "{I want what's between the curly braces}"

查看:268
本文介绍了正则表达式在花括号之间获取字符串“{我想要花括号之间的内容}”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,尽管我一年中至少有一次尝试学习正则表达多年,但我总是忘记,因为我很少使用它们。今年我的新年决心是不再尝试再学习正则表达式 - 所以今年为了让我免于流泪,我会把它交给Stack Overflow 。 (去年圣诞节混音)。

Unfortunately, despite having tried to learn regex at least one time a year for as many years as I can remember, I always forget as I use them so infrequently. This year my new year's resolution is to not try and learn regex again - So this year to save me from tears I'll give it to Stack Overflow. (Last Christmas remix).

我想以这种格式传递一个字符串 {getThis} ,并且返回字符串 getThis 。任何人都可以帮助坚持我的新年决议吗?

I want to pass in a string in this format {getThis}, and be returned the string getThis. Could anyone be of assistance in helping to stick to my new year's resolution?

Stack Overflow相关问题:

Related questions on Stack Overflow:

  • How can one turn regular quotes (i.e. ', ") into LaTeX/TeX quotes (i.e. `', ``'')
  • Regex: To pull out a sub-string between two tags in a string
  • Regex to replace all \n in a String, but no those inside [code] [/code] tag

推荐答案

如果您的字符串将始终采用该格式,则为正则表达式是过度杀伤:

If your string will always be of that format, a regex is overkill:

>>> var g='{getThis}';
>>> g.substring(1,g.length-1)
"getThis"

这篇关于正则表达式在花括号之间获取字符串“{我想要花括号之间的内容}”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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