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

I need a regex pattern to match a string before decimal number.I need the output exactly as below example


sample outputs:

text.33
sample.51











Thank You!
Posted
Comments
Krunal Rohit 23-Jan-14 8:33am    
What have you tried so far ?

If you want regex pattern for the following sample outputs:
text.45
example.90
value.46
then try:
\b[a-zA-Z]*[.][\d][\d]\b

Else if you only want those alphabets:
text
example
value
then try:
\b[a-zA-Z]*(?=[.][\d][\d]\b)


+++++++++++++++++++++++++++++++++++++++++
[amended upon re-understanding]
\b[a-zA-Z]+[.][\d][\d]\b

actually just need to change the '*' to '+'
 
Share this answer
 
v5
Comments
Member 10391350 23-Jan-14 23:28pm    
I want both alphabets as well as number after dot or decimal.
Member 10391350 23-Jan-14 23:34pm    
I am getting my output with this pattern "\b[a-zA-Z]*[.][\d][\d]\b" but if there is no text or alphabet before decimal it should not be displayed in output.
example:
example.90
value.46
.09
.78
this is output i am getting when i used your pattern.
but desired output is:
example.90
value.46
Peter Leow 24-Jan-14 0:16am    
Wow, very difficult to understand your question, even your example did not tally with your question. Let me try to re-understand, so if the value is 'example.90', you want the output to be 'example.90'; if the value is '9.90' or '.90', you do not want any output. If that correct? then see my amended solution 2.
Member 10391350 24-Jan-14 0:27am    
Thanks a lot!and sorry for confusing you.Thanks a lot once again!
Member 10391350 24-Jan-14 2:18am    
I need another one help.
I need a pattern for finding any characters before decimal point except numeric values.
sample input:
1.9876
test.3456
45.4
page.6457
Output:
test.3456
page.6457
Try:
[^\d]*\d+
 
Share this answer
 
Comments
Member 10391350 23-Jan-14 9:14am    
Thanks for your reply......
I need only string before decimal or floating numeric values
sample outputs:
text.45
example.90
value.46
like that
OriginalGriff 23-Jan-14 11:13am    
Try giving an example of exact inputs and exact outputs - because it isn't clear from your comment what you want to get from what. All you show are "outputs" - which the regex I gave will provide!
Member 10391350 23-Jan-14 23:17pm    
Input Text:
Lipids have diverse structures.09 but are similar in that they are insoluble.23 in water.These diseases are known as the sphingolipidoses, or gangliosidoses. The sphingolipidoses are summarized in Table 7.1.

Output:
structures.09
insoluble.23


the pattern you suggested provides:
Table 7.1

I only want output as string before floating point no.(i.e table.1 is expected and not table 7.1)
OriginalGriff 24-Jan-14 4:38am    
Try this:
\s+[^\d\s]*?\.\d+
From your sample data is gives just
structures.09
insoluble.23

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