To make it clear, this is just part of what my Input string can be, therefor its important the regex work as a bool, since I only wanna change the input if it looks like v1 & v2.
Got a string input that can be writtin like this.
(Just an example, it’s not ip adresses I’m working with)
string v1 => "192.168.0.1"
string v2 => "192 168 0 1"
string v3 => "19216801"
I have to rewrite the first 2 versions into version 3
Im thinking something like this.
version 1
If input is of lenght X and only contains numbers and dots
Then Replace(".", "").
version 2
If input is of lenght x and only contains numbers and whitespaces
Then Replace(" ", "").
How would it look in a more precise regex?
3 numbers and (1 dot or whitespace)
and 3 numbers and (1 dot or whitespace)
and 1 number and (1 dot or whitespace)
and 1 number
Try this expression
and replace with
See it here on Regexr
^anchors on the start of the string$anchors on the end of the string\d{3}matches 3 digits (accordingly\dmatches one digit)[. ]is a character class matching either a dot or a space.