Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Need expression to find mixed number in string.

I am looking for a regular expression pattern that will find mixed numbers as in below:

1 1/2
12 2/3
2 11/13

There is a white space between the whole number and fraction. This is to be used with VB.net code.
0
NevSoFly
Asked:
NevSoFly
1 Solution
 
MazdajaiCommented:
Try

(^\d{1,2}\s\d{1,2}\/\d{1,2}$)

Open in new window

0
 
NevSoFlyAuthor Commented:
Thanks for your help.  Unfortunately I for got to add that I was attempting to replace the white space in the string between the whole number and fraction with ":".

My apologies for such poor communication.
0
 
käµfm³d 👽Commented:
Put capturing parentheses around each component. Then replace with what was captured.

e.g.

Dim result As String = System.Text.RegularExpressions.Regex.Replace(source, "(\d+)\s*(\d+)\s*/\s*(\d+)", "$1:$2/$3")

Open in new window

0

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now