1

I have strings like is below,

nn"h11p3ppppvxq3b288N1 m 227"] {vanxtageendganmesbhorgtgt(1702)}' d3zd6xf8dz8xd6dz8f6zd8`

[nn"5rvh11p3ppppvxq3b288N1 n 227"] {vanxtageendganmesbhorgtgt(1802)} d3zd6xf8dz8xd6dz8f6zd8

I start my 1st capturing group from m 227 till end of third line, And my 2nd group from n 227 till end of third line ..... Now I want to add some digits to end of first captured group , say it -22 And some digits to end of second captured group, say it -11
My first regex can match and works separately so 2nd as well .... but to make them combine with | it doesn't .....

Search: (m\s.*\n.*\n.*)
Replace: $1 -22

My combined regex is as below

(m\s.*\n.*\n.*|n\s.*\n.*\n.*)

Replace: $1-22 $2-11

But this will add (-22 -11) to both intendeds ...

I want the output to be as below

nn"h11p3ppppvxq3b288N1 m 227"] {vanxtageendganmesbhorgtgt(1702)} d3zd6xf8dz8xd6dz8f6zd8 -22

[nn"5rvh11p3ppppvxq3b288N1 n 227"] {vanxtageendganmesbhorgtgt(1802)} d3zd6xf8dz8xd6dz8f6zd8 -11

I have used | or for to combine both regexes to works as one for the purpose of time Savage ....

Any help will be appreciated

Haji Rahmatullah
  • 390
  • 1
  • 2
  • 11

1 Answers1

1

You can use

Find What: ([mn])\s.*\R.*\R.*
Replace With: $& -$1

Details:

  • ([mn]) - Group 1 ($1): m ior n
  • \s - a whitespace
  • .*\R.*\R.* - a line, a line break, then again a line and a line break and then a line.

The $& in the replacement is the backreference to the whole match.

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Thank you very much Wiktor, , as I'm new user, please teach me how to give thanks or a badge? – Haji Rahmatullah Feb 20 '21 at 17:30
  • What if I wanted to add 22 to m and 11 to n ? What will be the backreferance and regex? Thanks once again – Haji Rahmatullah Feb 20 '21 at 17:56
  • @حاجيرحمتالله Find `(?:(m)|n)\s.*\R.*\R.*` and replace with `$& -(?{1}22:11)`, if I understood you well. – Wiktor Stribiżew Feb 20 '21 at 17:59
  • Sorry didn't work as was desired it just added -(?{1}22:11), ,,, I'm using a mobile notepad version called notepadmm – Haji Rahmatullah Feb 20 '21 at 18:08
  • 1
    @حاجيرحمتالله Use the Notepad++ full version if you need a conditional replacement. Else, it is not possible. – Wiktor Stribiżew Feb 20 '21 at 18:13
  • At first I considered your answer helpful, but it was charming, I still need an answer as intended, I'm sorry for my English, I started my captured group one from M till two last lines, so I want to add at the third line which is end of my first captured group a desired digits,,,, and so a different desired digits to second's captured group as well....but your answer was charming looking as I gave the example, but not as I wanted.... – Haji Rahmatullah Feb 21 '21 at 02:24