FAQ Database Discussion Community


Unclosed Group Error with Parentheses when Replacing an Expression

java,regex,replace,parentheses
So I am trying to make a custom variant of the ScriptEngineManager's engine.eval() by reading a string before evaluating it. I want to turn the expression 3(4) into 3*(4) so the engine.eval() can read it. So I attempt using this method: String string = 3(4); String[] numbers = string.split("\\)|\\*|/|\\+|-"); if...

Regexp replace everything between parenthes

ruby,regex,replace,parentheses
I would like to know if anyone can help me figuring out a regex that replaces everything within parentheses. My examples are: grouping(elllo) grouping(function() { console.log("hello") }) So, I would like to replace everything inside () matching the grouping. I only went to this stage: \bgrouping(\(([^)]+)\)) However, it doesn't match...

Indices of matching parentheses in Python

python,parentheses
Is there a way to get indices of matching parentheses in a string? For example for this one: text = 'aaaa(bb()()ccc)dd' I'd like to get a dictionary with values: result = {4:14, 7:8, 9:10} which means that parentheses on index 4 and 14 are matching , 7 and 8 an...

Defining variable with multiple values in parentheses uses 2nd value [duplicate]

javascript,variables,parentheses
This question already has an answer here: Javascript expression in parentheses 2 answers Right so my question is: var x = (val1,val2); sets the value of x to val2; Why?...

Find String Inside Outermost Parenthesis

c++,string,nesting,parentheses,repetition
Say that I have a string which contains both multiple sets and nesting of parenthesis. I want to extract only the string in the first parenthesis encountered, including whatever nested parenthesis it contains. For example: this (is(maybe)) a test (and maybe not) I want to extract: is(maybe) I believe this...

clojure terminating paranthesis syntax

clojure,compiler-construction,parentheses
Is there any reason why the expression (foo5 (foo4 (foo3 (foo2 (foo1 arg))))) cannot be replaced with (foo5 (foo4 (foo3 (foo2 (foo1 arg)-) or the like, and then expanded back? I know lack of reader macros means that you cannot change syntax, but can this expansion possibly be hard coded...

Is it mandatory to enclose an entire ternary operator statement in parenthesis in this statement?

php,ternary-operator,parentheses,readability,code-readability
For example in the following statement, $class = ( is_array($tagClasses) ? 'class="'.implode(" ",$tagClasses).'"' : '' ); is the outermost parentheses only for readability or does it really have any other purpose? I think it is for readability and code-aesthetics only, unless you have other things happening in the same statement,...

Extract data from within parenthesis in python

python,dictionary,parentheses
I know there are many questions with the same title. My situation is a little different. I have a string like: "Cat(Money(8)Points(80)Friends(Online(0)Offline(8)Total(8)))Mouse(Money(10)Points(10000)Friends(Online(10)Offline(80)Total(90)))" (Notice that there are parenthesis nested inside another) and I need to parse it into nested dictionaries like for example: d["Cat"]["Money"] == 8 d["Cat"]["Points"] = 80 d["Mouse"]["Friends"]["Online"] ==...

Parentheses in string of javascript function call

javascript,jquery,syntax-error,parentheses
I have a loop that creates links with a javascript function call in the onClick events and uses the text returned from a database as one of the parameters. My issues I am having is that sometimes this text being returned has parenthesis in them which is causing a syntax...

how to change the value of sp-navigate-reindent-after-up in smartparens

emacs,lisp,elisp,parentheses
I want to change the default behavior of smartparens to remove the whitespace before the close delimiter. I mean, when I type ) after (a b c |, I hope the final result is (a b c)|. Here, the | is cursor. I searched the documentation of smartparens, and find...

Do parentheses make a difference when determining the size of an array?

c,arrays,language-lawyer,sizeof,parentheses
The following program prints the same number twice on gcc 4.8.2: #include <stdio.h> int main() { char a[13]; printf("sizeof a is %zu\n", sizeof a ); printf("sizeof(a) is %zu\n", sizeof(a)); } According to this reddit post, gcc is not standard-conformant in this respect, because a parenthesized expression is not on the...

AS3 switch/case difference with or without parenthesis

actionscript-3,switch-statement,case,parentheses
In AS3 it is possible to write code without parenthesis, like such switch(letter) { case "A": // some code break; case "B": // some more code break; } or with the parenthesis, like this switch(continent) { case "A": { // some code break; } case "B": { // some more...