I have next input string:
ANIM "_NAME_KEY_" // Index = 26, AFrames = 1
{
0x301C
AF 0x201C 1 0 0 FREE_ROTATE 0 FREE_SCALE_XY 100 100
}
How can i get whole string between two curly braces, just having _NAME_KEY_ ?
Blocks: The code between a pair of curly braces within any method or class is called as blocks.
To match literal curly braces, you have to escape them with \ . However, Apex Code uses \ as an escape, too, so you have to "escape the escape". You'll need to do this almost every time you want to use any sort of special characters in your regexp literally, which will happen more frequently than not.
In writing, curly brackets or braces are used to indicate that certain words and/or sentences should be looked at as a group. Here is an example: Hello, please pick your pizza toppings {chicken, tomatoes, bacon, sausage, onion, pepper, olives} and then follow me.
Format strings contain “replacement fields” surrounded by curly braces {} . Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }} .
Use the option re.MULTILINE
as a second argument to your re.compile/etc. call.
I would propose this regex: _NAME_KEY_[^{]*+\{([^}]+)\}
Explanation:
_NAME_KEY_
: match "_NAME_KEY_"
[^{]*
: match as many non-{-characters as possible (greedy)
\{
: match a { character
([^}]+)
: match (and capture) non-}-characters (greedy)
\}
: match one } character
re.findall(r'(?<={)[^}]*',str)
E.g.
In [5]: x="""ANIM "_NAME_KEY_" // Index = 26, AFrames = 1
{
0x301C
AF 0x201C 1 0 0 FREE_ROTATE 0 FREE_SCALE_XY 100 100
}"""
In [6]: import re
In [7]: re.findall(r'(?<={)[^}]*',x)
Out[7]: ['\n 0x301C\n AF 0x201C 1 0 0 FREE_ROTATE 0 FREE_SCALE_XY 100 100\n ']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With