英文:
Get node value between curly braces with Java Pattern.compile()
问题
以下是翻译好的内容:
我想从以下字符串中提取id的值
.... code=1234random22211, request={ id='randomValue like: aa1a-bb2b-cc3c-ddd4d', event='new' version='1'} ...
我已经制定了以下模式:
Pattern p = Pattern.compile("/^.*code=" + currentCode + ", request=\\{([^}]*)");
Matcher m = eventIdPatterns.matcher(logs);
boolean idExists = m.matches();
该模式成功评估了代码:https://regex101.com/r/1kJ5Uo/2 但是我不知道如何在模式中去掉剩余的\
。
评估结果总是为false,因为模式p被视为:/^.*orderCode=20200409174150852, request=\{([^}]*)
。
有人可以告诉我如何在执行m.matches()
时摆脱模式中的额外\
,或者提供另一个提取id
值或花括号内内容的模式吗?
英文:
I want to extract the value of id from the following string
.... code=1234random22211, request={ id='randomValue like: aa1a-bb2b-cc3c-ddd4d', event='new' version='1'} ...
I have the made the following pattern:
Pattern p = Pattern.compile("/^.*code=" + currentCode + ", request=\\{([^}]*)");
Matcher m = eventIdPatterns.matcher(logs);
boolean idExists = m.matches();
The pattern evaluates the code successfully: https://regex101.com/r/1kJ5Uo/2 but I don't know how to get rid of the remaining \
in the pattern.
The evaluation is always false because pattern p is seens as: /^.*orderCode=20200409174150852, request=\{([^}]*)
.
Can somebody indicate me how to get rid of that extra \
from pattern when I perform m.matches()
or another pattern to extract the value of id
or the content between curly braces
专注分享java语言的经验与见解,让所有开发者获益!
评论