I'm going to put all decimal numbers in a text inside a span tag (`<span>`

) but the numbers are not using period as decimal separator, they use slash (`/`

)

The sample text is something like this:

There are 12/5 percent of students who...

And I want to convert it to

There are `<span>`

12/5`</span>`

percent of students who...

Actually I need the regular expression which matches.

The following regex will work for you, taking in count that the number will contain a `/`

:

```
[\d]+/[\d]+
```

The following code will do the trick:

```
string text = "12/5";
string pattern = @"\b[\d]+/[\d]+\b";
MatchEvaluator m = match => "<span>" + match.Groups[0] + "</match>";
Regex.Replace(text, pattern, m);
```

Try this:

```
resultString = Regex.Replace(subjectString, @"(?<!/)\d+(?:/\d+)?(?!/)", "<span>$0</span>");
```

It will work with integers and decimals. Numbers like `1/`

or `/1`

are not allowed, neither is something like `1/2/3`

.

**Explanation:**

```
(?<!/) # Assert that the previous character isn't a /
\d+ # Match one or more digits
(?: # Try to match...
/\d+ # a /, followed by one or more digits
)? # ...optionally.
(?!/) # Assert that the following character isn't a /
```

RegEx:

```
\D+((\d+)\/(\d+))\D+
```

Capture groups:

```
\1 12/5
\2 12
\3 5
```

Similar Questions

Basically I want to generate random numbers that won't ever repeat for a very long period (I don't want to use a sequence) like for example the LCG that java uses: synchronized protected int next(int

Is there any possibility to find a cycle length in very large portion of numbers (more than maximum value of bigest integer type in C/C++, let's say 2^20), without involving disk to perform it? The be

I am trying to sum my decimal records e.g. There is a column in my table named cash having values like 40.33, 30.00, 77.22. How can I create a query that sum up these records? I am trying hard using S

The numbers are generated randomly. In the specified range. For example, it is two numbers: 5 and 10, well 10 divides 5. If it's 5 and 2, it is not divide. The 2 required to reduce by 1 or 5 to increa

I am trying to get the total of my variables containing numbers, some may be decimals. I need this to be to two decimal places and am using the number_format() function. $total = $order->order->

I have a textbox which should accept input in the following format: [decimal], [decimal]; [decimal], [decimal]; [decimal], [decimal] For example: 0.01,0.10; 0.20,0.50; 1.00,3.00; 4.00,1000.00 My know

Possible Duplicate: Display two decimal places, no rounding I need to format the total result numbers in 2 decimal format. I am trying to achieve it without using jQuery plugin but just editing my f

I need to separate fractional part from BigDecimal and convert to Integer. Eg: 1.05(BigDecimal) => 5(int) 1.30(BigDecimal) => 30(int) Note: Decimal part won't exceed 2 digits

how do i get the numbers after a decimal point? for example if i have 5.55 how do i get .55?

In bash I am trying to code a conditional with numbers that are decimals (with fractions). Then I found out that I cannot do decimals in bash. The script that I have is as follows: a=$(awk '/average

In db I have strings like so 324/23/235 -> all numbers and slashes and fsg/23/234 -> NOT all numbers and slashes Now when I am in desgin view currently the criteria for this column is >0

I'm looking for preg_match_all pattern to find all URL on a page that don't have trailing slash. For example: if I have a href=/testing/abc/>end with slash a href=/testing/test/mnl>no endin

problem is with specified input, I have an input in which is something like this, -0.982983928391353 and i want to format that to -0.98298 ( upto 5 decimal points) this is the sample input xml below.

I am trying to take everything after the decimal and display it as a fraction. Couldn't find much for objective-c on how to accomplish this. I am using double for my formatting of variables, not sure

I want to to represent two numbers in A/B format,wWhere A and B are any integers. I want the decimal result in shortest format. Examples: The shortest decimal representation of 3/28 is 0.10(714285)

Though the representations of a number are somewhat a relative aspect, we generally use the decimal form when printing to the outer world. I'm in a Mac OS X, and while analyzing the source of libc I f

I have 4 valuables that are added as fractions n1 = input(Denominator 1) d1 = input(Denominator 1) n2 = input(Denominator 1) d2 = input(Denominator 1) def fraction(n1,d1,n2,d2): a = Fraction(n

$string =string string //deleteme string //deleteme // deleteme string; How to remove all the lines that begin with a double slash?

I have a JodaTime Period that I've created from two DateTime instants. Is there a good way to convert that Period into a decimal number of hours? For instance, I have a Period that goes from 1pm to 1:

One of my software's functions is to convert numeric strings into double datatype. I want to explicitly indicate the use of period (.) as a decimal point. Thus, no matter the language settings of the

I have a problem with decimal numbers. If I use .(dot) instead of ,(comma) in the textbox it comes null in controller. I know its a language issue because in spanish we use comma instead of dot for de

In Microsoft Excel 2007, given a date span, I want to find our what fraction of that date span lies within each season, which is obviously another date span. For example: Given a span of 26 Nov 10—

Possible Duplicate: How to know the repeating decimal in a fraction? Is there a way to tell if a decimal is terminating or repeating? Example: I have fraction: 1/3 and it's repeating decimal - 0.333

if my .SubItems(2).Text is 12.5 and [quantity] is 15 , then it is storing '3' instead of 2.5' , the data type of the quantity column is number with decimal format.. pls help me on this... update

I have a datatable column which contains a pair of two values (resolved/pending) seperated by forward slash '/' for eg : (10/22) ColumnABC --------- 1/2 5/8 1/3 Now I want to calculate sum of this co

I want to find the top 3 maximum repeated numbers in a Integer array? Below is the piece of code which I have tried but I couldn't find the desired result: static void Main(string[] args) { int[,] num

Possible Duplicate: Is there an equivalent for toPrecision() in Java? I created a method which suppose to limit the number to only 2 decimal places but what it does it shows numbers to 2 decimal pla

What's the simple way to remove more than 1 decimal number from source number . for example source numbers are : 1st source number is : 56.48216585224 2nd source number is: 93 Output must be : 1st

I was playing a bit with numbers, and something interesting came upon me, which I don't quite understand. public static void main(String[] args) { int hexNumber = 0x7A;//decimal: 122 binary:0111 1010

I'm working on localizing some strings in our application and we have text that looks something like: Factor f (1.0, 1.2, or 1.5) In a locale that uses a comma for the decimal point, would this be wr

I've got a bunch of numbers that have multiple decimal points (so they're really strings). However, I want to sort them as if they were numbers. 1.1.1 10.2.3 2.6.7 21.10.4 3.10.12 4.11.5 4.1.16 6.4.

I want to print floats in a good looking way. Specifically I want to print two numbers after the decimal point, but only if these numbers are not zero. This works if the number is not an even integer:

As part of a calculator app, I am trying to implement uses with sigma notation. However, the result it prints out is always a decimal, and the rest isn't important. I simply want to change the decimal

My program should convert decimal numbers to binary. For big numbers it is giving me a negative number not a binary number. Why is this? For example, if I supply 2321 I get 100100010001, which is fine

Is it okay to use floating-point numbers as indices or when creating factors in R? I don't mean numbers with decimal parts; that would clearly be odd, but instead numbers which really are integers (to

I am trying to convert calculations keyed in by users with decimal results into fractions. For e.g.; 66.6666666667 into 66 2/3. Any pointers? Thanx in advance

Could any of you help me with a regex to allow this: 123.123 123. 1323.2 1.2312 1,23 123123,32 123, 123412 so to sum up: only one decimal point, it can be the last one.. but most not be the first. b

I have a textarea that will have one or more pairings that look like this, Lat = 38.7970308 Long = -100.8665928 How can I extract the numbers using Javascript (negative sign included if there)? I wa

Description: Given an array consists of n positive integers, find the largest C which makes C=A+B. A,B,C are all in the given array. Example: 1 1 1 4 5 5 6 6 10 9 C=10 1 3 6 C=-1, This means the larg

I can't seem to figure this one out. I need to count how many numbers below a given number in which it is divisible. Here is what I've tried: public int testing(int x) { if (x == 0) { System.out.print

has it occurred to anyone that a simple std::cout might print a value in hex format when it is supposed to format just a decimal(like an integer)? for example, I have a line as : std::cout <<

I didn't find which of the rules cause this bug, my .htaccess is: RewriteEngine on Options -Multiviews RewriteCond %{HTTP_HOST} ^incinqueterre\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.incinqueterre\.

Is it possible to store a fraction like 3/6 in a variable of some sort? When I try this it only stores the numbers before the /. I know that I can use 2 variables and divide them, but the input is fro

I have a script that split the informations in a line, i've succeeded to split it and extract the informations i need but i have the slash that shows up :/ i'de like to get only what's after it here's

Trying to run a java program through Powershell. I go to my directory and use javac Part1.java and then to run the class I use java Part1 but it gives me this error Error: Could not find or load main

I'm looking for suggestions on the best way to achieve a diagonal slash across a page which will sit behind the main content area. I'd like to achieve this without images or additional markup and be a

I try to do some optimization on LLVM bitcode without generating final executable binary. I link all project bitcode.In this test there is no main function in bitcode, but LLVM needs to find a main fu

In my routes.rb I have: get projects/:category_id => projects#index When I write projects_path(1) the generated URL is /projects.1 instead of /projects/1. Do you know why this is happening? He

I'm having a problem with letting users enter numeric values in my textboxes which have the same class. What I Want: Allow users to enter only 2 numbers before the decimal points and another 2 after

I have a web service that returns a decimal value into my json string but it rounds it off on numbers that are 400.00 to 400 instead, but if it has 400.50 it returns 400.50 which is what i want how do