?
Solved

Regular Expression to capture two numbers using: ("(\d+),(\d+)")

Posted on 2005-03-25
7
Medium Priority
?
266 Views
Last Modified: 2010-04-23
To: All

Giving a string like (56, 78) or (342, 45)

I'm having troubles capturing the two numbers seperatly using regular expression

The expression: (\d+),(\d+) works in a regular expression checker but I can't get it to work in VB.NET

0
Comment
Question by:vaultworld
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13632051
try:

\(\d+\),\(\d+\)

parentheses (or whatever they're called) are special characters in regex, so you have to escape them
0
 
LVL 4

Expert Comment

by:imperial_p79
ID: 13632059
check if \(\d+\),\(\d+\) works!
0
 
LVL 4

Expert Comment

by:imperial_p79
ID: 13632065
hmm. i was typing that at the same time as you S-Twilley
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:S-Twilley
ID: 13632071
i think it's slightly wrong actually :P, will post up a better one in a sec
0
 
LVL 12

Accepted Solution

by:
S-Twilley earned 2000 total points
ID: 13632095
       Dim regBinaryCapture As New Regex("\((?<x>\d+),(?<y>\d+)\)", RegexOptions.IgnorePatternWhitespace)
        Dim testStr As String = "(35,56)"

        Dim matchTest As Match = regBinaryCapture.Match(testStr)

        If matchTest.Success Then
            MsgBox("X:" & matchTest.Groups("x").Value)
            MsgBox("Y:" & matchTest.Groups("y").Value)
        End If
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13632123
that's if you want to record the values with a named group.... my previous example was escaping parentheses in the wrong places...

to test for paired digits in brackets:     \(\d+,\d+\)

to group simply:                                \((\d+),(\d+)\)

to group with named group:               \((?<x>\d+),(?<y>\d+)\)
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13632162
you could even get away with ignoring the enclosing parenthesis... depending on whether you want to test for them or not i.e.

do you want   "36,54"   to be treated as ok... or is "(36,54)" the only proper structure:


if you want either way to work (with or without parentheses)... then use these:


to test for paired digits in brackets:     \d+,\d+

to group simply:                                (\d+),(\d+)

to group with named group:               (?<x>\d+),(?<y>\d+)

=========

I think that should be ok... the above though will pull out paired digits in any kind of string, like

"ABC DEF  34, 56 DJ DKD JFFF"
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question