1

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

5
  • 4
    Don't know about performance but [aa-zZ] does not match what you might expect Commented Dec 11, 2015 at 5:39
  • 1
    {1,}=+, {1}=empty, so [0-9]+[A-Za-z] Commented Dec 11, 2015 at 5:41
  • Use [0-9] instead of \d, Regex: [0-9]+[a-zA-Z] Commented Dec 11, 2015 at 5:42
  • Possible duplicate of \d is less efficient than [0-9] Commented Dec 11, 2015 at 5:47
  • you're right Avinash Commented Dec 11, 2015 at 6:00

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

3 Comments

I dont understand, wich RegEx i cant write ? big number : ([0-9]{1,})
{1,} is equivalent to +, so you are using a +... and * can also be written {0,}
1 to big number [1-9][0-9]*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.