c# - Using RegEx to find and replace doubles -
I want to replace all double tokens in the string with the double value added to the "c" letter. Is there an easy way to do this? I thought the way of regular expression is
For example, I want to change
treand60 (12.3) / 1010 + 1> 1010
1 or more digits after a decimal point is
treand60 (12.3c) / 1010c + 1c> 123c
Any suggestions
$ _ = 'treand60 (12.3) / 1010 + 1> 1010' ; S / \ b \ d + (:. \ \ D +)? / $ & Amp; C / G; Print; # Output is 1 or more digits and then
"treand60 (12.3c) / 1010c + 1c> 1010c"
\ d +
. \ D +(?: ...)
is the last?
means "match zero or one of these" (i.e. this is optional). And\ b
means only on the boundaries of the word (it prevents matching of something like "Hello123" because the number comes straight after the word letter).Here is the C # equivalent:
system. Text. Regular Expression; // ... string input = "treand60 (12.3) / 1010 + 1> 1010"; Reggae Reggae = New Reggae (@ "\ b \ d + (?: \. \ D +)?"); String Output = Rex. Replay (input, (m) => m value + 'c'); Console.WriteLine (Production); // print is the Lambda expression inside the call "trend 60 (12.3c) / 1010c + 1c> 1010c"
call which only receives the mail text and adds 'C' . / P>
Comments
Post a Comment