How to write a find ane replace experssion
-
I am trying to add back some formatting removed by a stupid program and I thought I could write a search and replace expression to make all the text in the rest of the file look like the first 2 lines where there would be a CR break after the first number in one huge line of text. Any ideas?
17:30:19:>>> WELCOME TO TEMPE, ARIZONA,
17:30:22:THE WELLS FARGO ARENA, HOME OF
17:30:24:THE SUN DEVILS OF ARIZONA STATE17:30:26:UNIVERSITY.17:30:27:ASU GETTING SET TO TAKE ON17:30:29:KENNESAW STATE.17:30:30:PART OF THE LEGENDS -
Hello attathomeguy,
Easy enough, with regular expressions :-))
-
Open the Replace dialog ( CTRL + H )
-
SEARCH
.(?=\d\d:\d\d:\d\d:)
-
REPLACE
$0\r\n
-
Check the Regular expression search mode
-
Leave the . matches newline option UNchecked
-
if necessary, check the Wrap around option
-
Click on the Replace All button
Et voilà !
Notes :
-
The dot (
.
) represents any standard character ( different from\r
,\n
and\f
) -
The syntax
(?=\d\d:\d\d:\d\d:)
is called a look-ahead, that looks, after the dot, for 3 sets of two digits, each of them followed with a colon. However, although this condition must be true, it’s NEVER part of the regex to be replaced. Therefore, the search regex is, only, the character just before the time syntax HH:MM:SS. -
The
$0
, in the replacement part, represents the entire regex matched, that is to say, the dot, which must be separated, from the HH:MM:SS form, with a line break (\r\n
). If you use UNIX files, just change\r\n
into\n
.
So, the last line of your post :
17:30:24:THE SUN DEVILS OF ARIZONA STATE17:30:26:UNIVERSITY.17:30:27:ASU GETTING SET TO TAKE ON17:30:29:KENNESAW STATE.17:30:30:PART OF THE LEGENDS
will be replaced by the five lines below :
17:30:24:THE SUN DEVILS OF ARIZONA STATE 17:30:26:UNIVERSITY. 17:30:27:ASU GETTING SET TO TAKE ON 17:30:29:KENNESAW STATE. 17:30:30:PART OF THE LEGENDS
Best Regards,
guy038
P.S. :
You’ll find good documentation, about the new Boost C++ Regex library ( similar to the PERL Regular Common Expressions ) used by Notepad++, since the
6.0
version, at the TWO addresses below :http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html
-
The FIRST link explains the syntax, of regular expressions, in the SEARCH part
-
The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part
-
-
THANK YOU SO MUCH THAT WORKED GREAT!