How can I detect when a key {
is open and when it is closed }
? What I want to achieve is to detect opening and closing curly braces, but I would also like to be able to detect content within them.
Example:
{#f66} o {red}
Expected result:
- The keys:
{#f66}
and{red}
. - And the content:
#f66
andred
.
Regular phrase:
Description:
{
- Matches a literal brace opening([^}]*)
- Group 1 - Records the value of the text that was matched in a backreference. Coincides with:[^}]*
- Any character other than a}
, repeated 0 or more times}
- Matches a literal curly braceWhen using a group (with the parentheses), the result of RegExp.exec() will be an array with all the matches at index 0, and the result of the first group at index 1 (or more if we use more groups) .
Code:
For atom and to be able to know if your JavaScript syntax is correct, you have jslint. For the theme of colors, you have another plugin for Atom called color-picker. You can find them by searching Atom
If I understand correctly, you want to detect the value that is inside the curly braces, what you can do is use a regular expression and the method
match
that detects the opening curly brace{
, read what is inside (putting it in a parenthesis) and then the curly brace closing{
.Something like this
/{(.*)}/
you can see here:That will return an array with the string that matched the condition and the value inside the curly braces.