views:

48

answers:

3
+1  Q: 

Regex in Notepad++

Hi all,

I have a range of files of a specific format. I have pasted an example here.

----------------------------------------------
Attempting to factor n = 160000000000110400000000018963... Found a factor: 400000000000129
Time (s): 18.9561
----------------------------------------------
Attempting to factor n = 164025000000137700000000028819... Found a factor: 405000000000179
Time (s): 22.3426
----------------------------------------------
Attempting to factor n = 168100000000155800000000036051... Found a factor: 410000000000197
Time (s): 101.183

I would like a regular expression that I can use to capture the times, e.g. for all the lines with format "Time (s): X.Y" I want to keep X.Y on a seperate line, and throw EVERYTHING ELSE away.

I have the following expression: Time (s)\:\s+(\d+.\d+), which captures these. This captures the lines I need, but Notepad++ only seems to have functionality to replace with something, not save what it matches. So I can remove all those lines, which is nearly the opposite of what I want.

Any help?

+1  A: 

Use this on the command line:

for /f "usebackq tokens=3" %a in (`findstr /b "Time" 1.txt`) do @echo %a
Joey
+1  A: 

Well I don't know Noteplad++ but its likely that you can use the result of capture groups in the replacement field. Either try

\1

or

$1

1 = first capture group. So you basically replace the whole line with \2 in your case.

SchlaWiener
I think they want to remove the lines in between as well.
Joey
A: 

Use the following expression to match the entire line:

.*\(s\)\:\s+(\d+.\d+)

Now you can replace this with

\1

which gives you the matched group number 1 (the only group in the above expression) that matches the time

executor
I want to remove the lines in between as well.
Martin Lauridsen
Nvm I wrote a program that does it for me.
Martin Lauridsen
^^ As soon as you try multi-line processing with regular expressions, it is usually easier to write a program
executor
That's true. You cant tell regex "replace a empty line with Backspace" ;)
SchlaWiener