0

Trying to figure out the regular expression to be used in Notepad++ where I can search the text below (as an example) and find the results in order.

Sample Text:

{ USERECOVERDB 1 }

protocol to_nuance_orm_p5 {
{ AUTOSTART 1 }
{ DELAYCONNECT 0 }
{ HOST 198.92.118.168 }
{ IPV4_V6_DUAL 0 }
{ PDLTYPE tcp-client }
{ PORT 9014 }
{ PRIVATE_KEY {} }

Desired result:

protocol to_nuance_orm_p5
HOST 198.92.118.168
PORT 9014
  • Please look at the preview before posting and use formatting, your question was completely unreadable before @snowdude fixed it. – gronostaj Jul 3 '14 at 9:58
  • 1
    Are those asterisks actually in your text or is it your formatting? – gronostaj Jul 3 '14 at 10:02
  • No, the asterisks are not in my code. I had it the way I did on purpose. I'll clean it up to the original. – Ron Ortiz Jul 7 '14 at 15:03
1

Following regex should work:

protocol [^ ]+|HOST \d+\.\d+\.\d+\.\d+|PORT \d+

I'm using Sublime Text to test it, but it should work in Notepad++ too.

Here's how it works: it's composed from three parts:

  • protocol [^ ]+
  • HOST \d+\.\d+\.\d+\.\d+
  • PORT \d+

| symbol means that any of those parts can be matched.

First part: protocol [^ ]+

protocol (including the space after l) simply matches the word protocol and following space. [^ ] matches one non-space character and + means to match one or more preceding symbols, so [^ ]+ will match one or more non-space symbols.

Second part: HOST \d+\.\d+\.\d+\.\d+

HOST matches text just like in the first part. Then there's \d which matches one digit and + which has the same meaning as above. \. will match regular dots. Unlike with letters, a dot has to be preceded with a backslash, because it has a special meaning in regular expressions.

Third part is even simplier than the second one, so I don't think explainations are necessary.

If you want to learn more about regular expressions, this tutorial is quite good and here's a good regex tester/debugger.

  • You should be experienced enough to know that such one-liners are frowned upon, in this site. Please explain, albeit briefly, why this is supposed to work. – MariusMatutiae Jul 7 '14 at 16:26
  • WOAH! Now that is slick!!! Looks beautiful! Thanks!!! – Ron Ortiz Jul 7 '14 at 19:34
0

If you just want to find all text in the format:

** TEXT ** 

try this:

\*\*.*\*\*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.