Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am parsing a list of code numbers, they have a pattern of 12345.1211. They are space delimited. They sometimes will have a space followed by one - three addition number patterns like: 1221.121 11 or 111.111111 874.95 1211

I have a regex [0-9]+\.[0-9]+

It finds a decimated number like 12345.1211 as . I encapsulate the regex with ( & ) and use \1\n to break each code with a newline.

I am using Notepad++ with find an replace. But the regex falls short with the space-included numbers. The extra numbers endup on the same line as the next pattern.

Example of 1221.121 11 or 111.111111 874.95 1211 456.155


11 111.111111


1211 456.155

Is there anything I can do to optionally include the extra numbers separated by a space?


share|improve this question
The list is space delimited, yet you have codes that include spaces? – Excellll Feb 1 '12 at 14:28
If it is space delimited but the pattern needs to sometimes (but only sometimes) include spaces, then you will need to rigorously define when a space needs to be included and when it does not. If the definition is precise and accurate enough, then you could probably write a regex, but without that definition it isn't really possible to write one that would be 100% correct. – EBGreen Feb 1 '12 at 14:54
Also posting the exact regex that you are currently using will help us understand better what you are trying to do and where a fix might need to go. – EBGreen Feb 1 '12 at 14:57
The regex that I am using is listed, and highlighted. The list is space delimited, because it was copied from a webpage. In my example data sets, a valid CODE number shouldn't have a space in it. However my employer has made exceptions to that rule. Anytime there is a CODE number with a space, it typically has one space followed by two numbers. But there have been examples where it trailed with one or three digits. But those are even rarer. – TheSavo Feb 1 '12 at 16:39
I think I may have found the answer my self. If it run the regex: ([0-9]+) , which leads with a space, and trails with a space will only find a number pattern that has a space in front and behind it. Since valid Code Numbers will have a decimal, this will only find, what would be the extra digits. I wrapped it in parens, and use a back reference, lead it with an underscore, and trail it with a space. '\1 ' So it will attach the extra digits to the parent, and delimit the whole string with a space. I then add and undersore to my regex pattern like so. "([0-9]+\.[0-9]+) " – TheSavo Feb 1 '12 at 17:44

On your test data this regex matches all the numbers perfectly for me;


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .