Ror*_*ker 2 .net regex extract token
我需要从给定的字符串中提取用大括号标记的标记.
我已经尝试使用Expresso来构造一些可以解析的东西......
-------------------------------------------------------------
"{Token1}asdasasd{Token2}asd asdacscadase dfb db {Token3}"
-------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
并生成"Token1","Token2","Token3"
我试过用..
-------------------------------------------------------------
({.+})
-------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
......但这似乎与整个表达相匹配.
有什么想法吗?
尝试
\{(.*?)\}
Run Code Online (Sandbox Code Playgroud)
The \{ will escape the "{" (which has meaning in a RegEx). The \} likewise escapes the closing } backet. The .*? will take minimal data, instead of just .* which is "greedy" and takes everything it can.
If you have assurance that your tokens will (or need to) be of a specific format, you can replace .* with an appropriate character class. For example, in the likely case you want only words, you can use (\w*) in place of the (.*?) This has the advantage that closing } characters are not part of the class being matched in the inner expression, so you don't need the ? modifier).
归档时间: |
|
查看次数: |
4410 次 |
最近记录: |