Forum Moderators: phranque

Message Too Old, No Replies

Help optimising regex please

         

Mokita

5:48 am on Oct 12, 2010 (gmt 0)

10+ Year Member



I know only the utter basics, and struggle with writing optimised code.

Is this line the best it can be - or can it be shortened?

RewriteCond %{REMOTE_ADDR} ^216\.104\.([0-9]|1[0-9]|2[0-9]|3[01])\.

I'm wondering if the following will work:

RewriteCond %{REMOTE_ADDR} ^216\.104\.([0-9]|[12][0-9]|3[01])\.

The IP range I am targeting is 216.104.0.0 - 216.104.31.255

TIA!

sublime1

1:50 pm on Oct 12, 2010 (gmt 0)

10+ Year Member



Looks good to me.

jdMorgan

3:28 pm on Oct 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Even shorter - Make the "tens digit" optional for 10 through 29 and eliminate one 'Or' clause:

RewriteCond %{REMOTE_ADDR} ^216\.104\.([12]?[0-9]|3[01])\.

Jim

Mokita

12:30 am on Oct 13, 2010 (gmt 0)

10+ Year Member



Excellent Jim, thank you so much!