简体   繁体   English

大括号内的正则表达式值

[英]Regex values inside curly brackets

I have a random variable lets call it R inside a curly brackets like so: 我有一个随机变量,在大括号内将其称为R,如下所示:

{R}

I have tried to regex it with this: 我试图与此正则表达式:

{(.*?)//}

I then have this error 然后我有这个错误

"Caused by: java.util.regex.PatternSyntaxException: 
Syntax error U_REGEX_RULE_SYNTAX near index 1:"

Indicator targeting {(.*?)} "(" 指标定位{(.*?)} "("

I tried doing it without the brackets same error. 我尝试这样做,但没有括号相同的错误。 This time indicator targets "." 该时间指示器的目标是"."

Could someone help me find an alternate solution to regex items inside a curly brackets? 有人可以帮我找到大括号内正则表达式项目的替代解决方案吗?

尝试转义大括号:

String regex = "\\{(.*?)\\}";

Curly brackets are used in regexp to define specific sequence repetition. 在正则表达式中使用花括号定义特定的序列重复。

you have to escape them in the regexp. 您必须在正则表达式中将其转义。

\{(.*?)\}

should work better 应该更好地工作

Escape the {}s: 转义{} s:

String regStr = "\\{.\\}";

I've found this interactive regex testing page useful in refining Java regular expressions. 我发现此交互式正则表达式测试页面对完善Java正则表达式很有用。

Not entirely clear what you are trying to do by 不清楚您要做什么

\{.*\}

should work 应该管用

You can escape special characters using a backslash \\ . 您可以使用反斜杠\\来转义特殊字符。 See What special characters must be escaped in regular expressions? 请参见在正则表达式中必须转义哪些特殊字符? for more information (although there is no general rule). 了解更多信息(尽管没有一般规则)。 Try escaping the curly braces {} and slashes // . 尝试转义大括号{}和斜杠//

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM