cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
new-jmper
Level III

How to match number in parentheses?

The task is quite simple: extract number from a pair of parentheses in a string.

For example: "3" from "Abc_Def_Gh(3)_Ijk"

But I get "(3)" with formula Regex(:String_Column, "\(([0-9])\)").

So the questions is that how can I specify where the match start. Any pointer to more detailed JMP Regex document are welcome.

Thanks,

Dong


1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to match number in parentheses?

You need a second argument with a replace pattern. Otherwise Regex() returns the result of the search.

Try something like this. Should retrieve integer of any length but only if inside parantheses.

my_string = "Abc_Def_Gh(12)_Ijk_45";

Num( Regex( my_string, "\((\d+)\)", "\1" ) );

View solution in original post

2 REPLIES 2
ms
Super User (Alumni) ms
Super User (Alumni)

Re: How to match number in parentheses?

You need a second argument with a replace pattern. Otherwise Regex() returns the result of the search.

Try something like this. Should retrieve integer of any length but only if inside parantheses.

my_string = "Abc_Def_Gh(12)_Ijk_45";

Num( Regex( my_string, "\((\d+)\)", "\1" ) );

new-jmper
Level III

Re: How to match number in parentheses?

Many thanks! I missed the optional <format>.

     Regex(source, regular expression, <format>, <IGNORECASE>);

Dong

Recommended Articles