Rethic
Rethic

Reputation: 1081

regex - Removing text from around numbers in Notepad++

I have a large subset of data that looks like this:

MyApp.Whatever\app.config(115): More stuff here, but possibly with numbers or parenthesis...

I'd like to create a replace filter using Notepad++ that would identify and replace the line number "(115):" and replace it with a tab character followed by the same number.

I've been trying filters such as (\(\d+\):) and (\(\[0-9]+\):), but they keep returning the entire value in the \1 output.

How would I create a filter using Notepad++ that would successfully replace (115): with tab character + 115?

Upvotes: 2

Views: 692

Answers (3)

Jared Phelps
Jared Phelps

Reputation: 473

Replacing (\(\d+\):) with \t\1 will keep the parenthesis and the colon since you've included them in the group (the outer parenthesis), and I think that's what you mean by "they keep returning the entire value."

Instead of escaping those inner parenthesis, escape the outer ones like the other answers have suggested: \((\d+)\): - this says to match a left paren, then match and capture a group of digits, then match a right paren and a colon. Replacing that with \t\1 will get rid of the parens and colon that were not in the captured group.

Upvotes: 1

Kent
Kent

Reputation: 195289

this should work for your needs

replace

\((\d+)\):

with

\t$1

Upvotes: 1

Zach Leighton
Zach Leighton

Reputation: 1941

Use a quantifier.. (\(\d+?\):) where the ? will prevent it from being greedy. Also, since everything is in a () it will group it all and treat it as \1 ..

If it was in perl I'd say \((\d+?)\): which should match only the inner part.

Edit:

Just talked with my colleague - he said s/\((\d+)\)/\t\1/ and if you needed app config in front you could just put that in the front.

Upvotes: 2

Related Questions