• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 604
  • Last Modified:

Regular Expression - how do i exclude brackets from result

Hi, new to regular expressions. Basically a non-programmer.
Please help me with the following:

This is my string:
expertsExchange(269087);">

From this I need just the number 269087 and nothing else.

I have tried my best but I always end up with (269087)

Thanks for your help in advance.

0
greazedlightning
Asked:
greazedlightning
  • 6
  • 5
  • 3
  • +2
1 Solution
 
xRalfCommented:
Try this .*(\d+).*

Capturing group 1 should contain your number.
0
 
greazedlightningAuthor Commented:
I tried this:

expertsExchange(.*(\d+).*);">

and got this:

Match count: 1
Match[1][0]=expertsExchange(269087);">
Match[1][1]=(269087)
Match[1][2]=7
0
 
silemoneCommented:
you can use split and separate delimit with a delimit array that includes '(',')'

this would mean that your number would be array item 1;
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
silemoneCommented:
0
 
silemoneCommented:
          Just change to vb.net or let me know which language you are writing code in.
 
           string input = @"expertsExchange(269087)";
            char[] delimiters = { '(', ')' };
            string[] parts1 = input.Split(delimiters);
0
 
käµfm³d 👽Commented:
Depending on your language, you should be able to simply use:

\d+

Open in new window

0
 
silemoneCommented:
well grouping definitely works, but this is writen in C#:

Regex r = new Regex(@"([a-zA-Z\(]*)([0-9]*)([a-zA-Z)]*)(.)*");
Match m = r.Match("expertsExchange(269087);\">");
Console.WriteLine("Tag: {0}, InnerText: {1}", m.Groups[1].Value, m.Groups[2].Value);
0
 
Todd GerbertIT ConsultantCommented:
I'm with kaufmed - http:#a35234515

No need to over-think it, that pattern will match any group of 1 or more consecutive decimal digits, and since there's only one spot where numbers occur in your string, and they're what you're interested in, voila!
0
 
Todd GerbertIT ConsultantCommented:
(Don't gimme any points for that comment above, I just wanted to reinforce kaufmed's as your best option)
0
 
käµfm³d 👽Commented:
No need to over-think it...


Yeah, I'm lazy and I don't like to type, so the shorter the better   ; )
0
 
greazedlightningAuthor Commented:
@silemone

I need this for jmeter which uses Apache Jakarta ORO
http://jakarta.apache.org/jmeter/usermanual/regular_expressions.html
http://jakarta.apache.org/oro/

This is similar to PERL.

Can you whip this up in perl?
0
 
silemoneCommented:
I know some perl...try -
$phrase=~ m/([a-zA-Z\(]+):(\d+):([a-zA-Z)]+)(.)*/;
$numExtracted = $2;

0
 
silemoneCommented:
Corrected

I know some perl...try -
$phrase="expertsExchange(269087);\">"
$phrase= ~ m/([a-zA-Z\(]+):([0-9]+):([a-zA-Z\)]+)(.)*/;
$numExtracted = $2;
0
 
käµfm³d 👽Commented:
Funny, even after looking over the documentation, I don't see anything to indicate the pattern I offered wouldn't work. It even worked in their online tester.
untitled.PNG
0
 
käµfm³d 👽Commented:
I should note that it will only succeed for a "contains" search and not a "matches" search. You would need to modify the pattern a bit for a "matches" search (see below).


Result will be in 1st capture group.
.*?(\d+).*

Open in new window

untitled.PNG
0
 
greazedlightningAuthor Commented:
Brilliantly done kaufmed. Simple and spot on. This is my first question on experts exchange.
Can you direct me toward some easy to understand tutorials on regex?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 6
  • 5
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now