user1874594 user1874594 - 7 months ago 32
Bash Question

Pattern regex substitution in Notepad++

How do I achieve this kind of regex substitution in Notepad++ & Linux / Unix Korn shell (Plain BSD Linux)?

z1.9z.01.01 Yabdadba do
da.8p.25.7p Foobar
tg.7j.75.2q Whatever
90.6q.88.zx Jane Doe


Note the
char. I am not sure what you want to call it.

Substitution #1

o/p should be

Yabdadba do
Foobar
Whatever
Jane Doe


Substitution #2

o/p should be

9z Yabdadba do
8p Foobar
7j Whatever
6q Jane Doe


Substitution #3

o/p should be

z1.9z.01.01
da.8p.25.7p
tg.7j.75.2q
90.6q.88.zx


I tried using
^.*
and
$
with the regex option, but it won't do anything.

sln sln
Answer

Using the assumption that the parts are fixed and of this form XX.XX.XX.XX

For Substitution # 1
Find (?m)^[^.\s]{2}(?:\.[^.\s]{2}){3}[^\S\r\n]+(?=\S.*)
Replace nothing

 (?m)                          # Multi-line mode
 ^                             # BOL
 [^.\s]{2}                     # Four parts separated by dot's
 (?: \. [^.\s]{2} ){3}
 [^\S\r\n]+                    # Whitespace following
 (?= \S .* )                   # Must be some text here

For Substitution # 2
Find (?m)^[^.\s]{2}\.([^.\s]{2})(?:\.[^.\s]{2}){2}(?=[^\S\r\n]+\S.*)
Replace ' $1 '

 (?m)                          # Multi-line mode
 ^                             # BOL
 [^.\s]{2}                     # Four parts separated by dot's

 \. 
 ( [^.\s]{2} )                 # (1)
 (?: \. [^.\s]{2} ){2}
 (?=                           # Whitespace following
      [^\S\r\n]+ 
      \S .*                         # Must be some text here
 )

For Substitution # 3
Find (?m)^([^.\s]{2}(?:\.[^.\s]{2}){3})[^\S\r\n]+\S.*
Replace $1

 (?m)                          # Multi-line mode
 ^                             # BOL
 (                             # (1 start), Four parts separated by dot's
      [^.\s]{2} 
      (?: \. [^.\s]{2} ){3}
 )                             # (1 end)
 [^\S\r\n]+                    # Whitespace following
 \S .*                         # Must be some text here