Regex help
-
Good Afternoon,
Using Regex: How to replace with space blank the characters from position 25 to position 43 in a entire rows of a file ?
Thanks. -
FIND =
(?-s)^.{24}\K.{18}
REPLACE =\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
(using\x20
instead of spaces for easy copy/paste from the forum; it will work either as 18 copies of\x20
or 18 spaces in the replacement field;\x20
is another way of saying the-space-character)
SEARCH MODE = regular expression
REPLACE ALLThis will replace 25 (one more than 24 in the braces) to 43 (which is a total of 18 characters) with 18 spaces
----
Useful References
-
@peterjones Thank you.
-
Hello, @jose-emilio-osorio, @peterjones and All,
As the OP want to replace the
43th
column with aspace
char, as well, I suppose that the correct regex S/R is :-
SEARCH
(?-s)^.{24}\K.{19}
-
REPLACE
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
Now, here is a workaround when the REPLACE field must contain some
space
characters :SEARCH : (?-s)^.{24}\K.{19} REPLACE : ( )
-
Tick the
Wrap around
option -
Select the
Regular expression
search mode -
Click once on the
Replace All
button ( Do not use theReplace
button, because of the\K
feature )
Best Regards,
guy038
P.S. :
For instance, you could use this regex S/R :
SEARCH : (?-s)^.{24}\K.{19} REPLACE : ( text replaced )
-
-
Stupid fence post. In my head while answering, I knew to add 1 to account for the 25::43 inclusive, but I obviously didn’t execute that +1 before typing up the reply. Sorry for the off-by-one error.