Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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