0

I want to allow * or Number only in my QLineEdit for IP Address.

My regular Expression is:

QRegExp rx ( "^(0|[1-9]|[1-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$" );

Which is find for IP Address, Now I want to allow * symbol for search IP Range.

i.e. 10.105.*.* to 10.107.*.* This treated as 10.105.0.0 to 10.107.255.255

AB Bolim
  • 1,997
  • 2
  • 23
  • 47
  • use `\*` and it will work – Valijon Jun 17 '14 at 07:02
  • Example: `print re.match("^(0|[1-9]|[1-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5])).1[0-9]{1,2}.(\*|[0-9]{1,3}).(\*|[0-9]{1,3})$","10.105.*.*")` – Valijon Jun 17 '14 at 07:07
  • I have tried like this `( "^(\*|0|[1-9]|[1-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$" )` but, it wont work. – AB Bolim Jun 17 '14 at 09:30
  • Can you give us your complete code? If you are trying to match `"^(\*|0|[1-9]|[1-9][0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$"` with `"10.105.*.*"` it will fail – Valijon Jun 17 '14 at 09:38
  • I have made custome IPAddress using QLineEdit and QLabel. This RegExp is for single block of ip address. I am using four QLineEdit and three QLabel to make single IP Address. QlineEdit for geting digit(ip) then QLabel for `dot`. (QLineEdit QLabel QLineEdit QLabel like this) – AB Bolim Jun 17 '14 at 09:53
  • try to add `\\*` or even `\\\\*` – Valijon Jun 17 '14 at 10:04
  • Both tried...:) It wont work. – AB Bolim Jun 17 '14 at 11:13
  • On your RegEx, are you using `.`(dots)? If yes, replace them by `\\.` – Valijon Jun 17 '14 at 13:13
  • No, I am not using .(dots), My RegEx allow Numbers only as per IP Range, like at value 0-255. – AB Bolim Jun 20 '14 at 10:09

1 Answers1

1

Try this Regex which matches IPAddress with * and/or between 0-255

Regex reg = new Regex("^((\\*)?|[01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.((\\*)?|[01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.((\\*)?|[01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.((\\*)?|[01]?\\d\\d?|2[0-4]\\d|25[0-5])$");

bool isMatch = reg.IsMatch("*.1.1.255"); //true
isMatch=reg.IsMatch("255.255.255.255"); //true
isMatch=reg.IsMatch("*.*.*.*"); //true
isMatch=reg.IsMatch("0.0.0.0"); //true
isMatch=reg.IsMatch("256.*.*.*);//false
isMatch=reg.IsMatch("2.2.455.*);//false
malkam
  • 2,337
  • 1
  • 14
  • 17