Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I'd like the regex to catch:
* Page.7545
* .212
* .12
* testDoc.21
* aw.3


But not:
* 1000.25
* 2.21
* 898


Right now I have

\b[a-zA-Z]+[.][\d][\d]\b


but its not helpful.Please provide me some solution
Posted

Try this:
^[a-zA-Z]*[.][\d]+\b
 
Share this answer
 
v2
Comments
Member 10391350 24-Jan-14 3:27am    
Thanks!
'Better teach one to fish rather than give him some fish'

Regarding regular expressions, my advise would be:

- describe precisely what you want as output; describe it with words, not by a non-exhaustive example
Applied to your specific example, this would give:
In any part of my input, find:
A sequence of any letter (capital or not) of any length, followed by a dot, followed by a sequence of any digit of any length


- use a tool to translate your description into a valid regular expression. I personnaly use Expresso[^] for that; this tool allows you to construct your regular expression using a graphical user interface, which is not luxury when the complexity of this expression starts growing. It also allows you to test your regular expression against several inputs, and validate it.

Just my 2 cents; hope this helps :) Good luck.
 
Share this answer
 
Comments
Member 10391350 24-Jan-14 6:46am    
thanks for your advice!
phil.o 24-Jan-14 7:42am    
You're welcome!
Let me re-phrase the condition for the regex to make sure I understood it correctly:
Begin of line or not a digit followed by a dot followed by one or more digits
^|[^\d]\.\d+
 
Share this answer
 
Comments
Member 10391350 24-Jan-14 6:46am    
i am not getting desired output with this pattern but anyway thanks as i got the solution for this.
'grep -E' tested solution:
[a-zA-Z]+\.[0-9]+|^[ \t]*\.[0-9]+
 
Share this answer
 
Comments
Member 10391350 24-Jan-14 6:42am    
Thanks for your solution its working fine.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900