Try this:
\( *\d+ *[-+*/] *\d+ *\)
It means:
- Match the character "(" literally.
- Match the character " " literally.
- Between 0 and unlimited times, as many as possible, giving back as needed (greedy).
- Match a single digit 0..9
- Between 1 and unlimited times, as many as possible, giving back as needed (greedy).
- Match the character " " literally.
- Between 0 and unlimited times, as many as possible, giving back as needed (greedy).
- Match a single character present in the list "-+*/".
- Match the character " " literally.
- Between 0 and unlimited times, as many as possible, giving back as needed (greedy).
- Match a single digit 0..9
- Between 1 and unlimited times, as many as possible, giving back as needed (greedy).
- Match the character " " literally.
- Between 0 and unlimited times, as many as possible, giving back as needed (greedy).
- Match the character ")" literally.
Examples:
var regExp = /\( *\d+ *[-+*/] *\d+ *\)/;
"7+(4*6)".match(regExp)[0]; // "(4*6)"
"(44/(2*( 1 + 3)))".match(regExp)[0]; // "( 1 + 3)"
"(54-(23+12))".match(regExp)[0]; // "(23+12)"