Regex replace exact 5 digit not more than that
-
Hi I want to replace only 5 digit (not less than or not more than) to “xxxxx” with Regex I tried - InputString = "sample1: 12345 – sample2 : 123456789" Dim regExp As Regex = New Regex("(\d{5})") regExp.Replace(InputString, "xxxxx") output - "sample1: xxxxx – sample2 : xxxxx6789" But i want as "sample1: xxxxx – sample2 : 123456789" if more than 5 digit , it must not replace.
-
Hi I want to replace only 5 digit (not less than or not more than) to “xxxxx” with Regex I tried - InputString = "sample1: 12345 – sample2 : 123456789" Dim regExp As Regex = New Regex("(\d{5})") regExp.Replace(InputString, "xxxxx") output - "sample1: xxxxx – sample2 : xxxxx6789" But i want as "sample1: xxxxx – sample2 : 123456789" if more than 5 digit , it must not replace.
Add a whitespace and an "end-of-line" indicator:
Dim regExp As Regex = New Regex("\s(\d{5})$")
And include the whitespace back in your replacement string. And in future: post VB in the VB forum, and C# in the C# forum?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Add a whitespace and an "end-of-line" indicator:
Dim regExp As Regex = New Regex("\s(\d{5})$")
And include the whitespace back in your replacement string. And in future: post VB in the VB forum, and C# in the C# forum?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
It was exactly a C# question and not VB. I wonder why this simple question have made all nervous! it was related to Fuzzy Logic and Fuzzy Expert Systems. Anyway, thanks a lot for your all answers.
You have replied to someone else's question. The question that was asked here was written in VB.
-
It was exactly a C# question and not VB. I wonder why this simple question have made all nervous! it was related to Fuzzy Logic and Fuzzy Expert Systems. Anyway, thanks a lot for your all answers.
If you look at the question I answered, you will see it is written in VB, not C#...
Dim regExp As Regex = New Regex("(\d{5})")
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...