Reputation:
I know a lot of syntax ( c#,c, vb and so on ) hence my head is pretty full.
So I tend to write regex like this
edit2 : change word RegRex
[0-9]{1,}[aA-zZ]{1,}
[0-9]{1,}[a-zA-Z]{1,}
No +
, ?
, \d
, ...
Is there performance issues with this syntax?
edit : This question is wider than /d
vs [0-9]
syntax
Upvotes: 1
Views: 63
Reputation: 28830
In terms of performance {1,}
and +
are equivalent, but the first has more characters to be read... And {1}
is not necessary. That won't make much difference though.
More generally, it is not a matter of preference. If you have to match a numeric ID made of numbers from 1 to a big number, without +
(or {1,}
, or *
using \d
twice), that will be difficult
\d+
or
[0-9]+
or
[0-9][0-9]*
if you prefer.
Besides, [aA-zZ]
matches a
, Z
(twice actually) and anything between A
and z
, including [
, ]
, _
... (see an ascii table)
Upvotes: 2