Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: RegEx
I know only the how to filter for a fixed length numeric series using RegEx like this \d{4} . But that's not I want because the series to be checked can have a various length.
Could you please give me as many solutions as possible?
Thank you very much!
Posted 15-Oct-11 20:11pm
Comments
SAKryukov at 16-Oct-11 2:15am
   
No, because "as many as possible" would take too much time. Could you suggest less resource-consuming question? :-) Besides, your question looks too simple even for one solution :-). What's the problem, I cannot get it? Why non-fixed length presents additional problem? Perhaps you could give a specific example.
--SA
King Boy at 16-Oct-11 2:56am
   
You can imagine a customized TextBox with additional filtering feature (right when typing in it). It has a property called RegEx for user to pass in a RegEx to filter for a desired formatted string. That's why the string (series) can be variable in length and RegEx for fixed length is not suitable. My problem is not how to filter but how to filter using REGEX.
Thank you very much!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Medhi is right -
\d*
will work - however, I would suggest
\d+
instead as it requires a minimum of one digit in order to match (\d* will match "A12" as three matches: NULL, "12", NULL - \d+ will only find the "12").
 
If you are going to use Regexes, then get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions.
  Permalink  
Comments
Mehdi Gholam at 16-Oct-11 3:04am
   
my 5!
King Boy at 16-Oct-11 3:15am
   
Thank you very much! It is really worth a try.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use the following for getting as many digits as there are :
\d*
  Permalink  
Comments
King Boy at 16-Oct-11 3:01am
   
Thank you very much! That must be exactly what I want!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I suggest \d+ (at least one digit)
 
but if you want to capture scientific numbers :
[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?
 
test it here :
http://www.regular-expressions.info/javascriptexample.html[^]
  Permalink  
Comments
King Boy at 16-Oct-11 3:17am
   
Thank you very much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 345
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,158
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 16 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100