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,\nand\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\ninto\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 LEGENDSwill 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 LEGENDSBest 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.0version, 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!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login