Find/Replace Goes Past Line End

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
rsborland
Posts: 2
Joined: Sat Jul 13, 2013 5:42 pm
Location: United States

Find/Replace Goes Past Line End

Post by rsborland »

I'm editing a text file - all lines end in 0D0A. Snippit of file is found below. I'm using Regular Expressions in TP 7.0.9.

I'm looking for lines with "m." followed by text and ";" in them. My find expression is ([^m\.]*)m\.([^;]*);(.*)\R (I've tried with and without "\R")

At line7, I expected the find to fail (no ";" before EOL) and move on - but it 'sees' the "m." and finds ";" in the next line! Obviously, I'm missing something. Can anyone identify?

sp:;Dorothy;b.Apr 1812;m.8 Sep 1828;d.4 May 1897)
2.;John;b.Abt 1831;d.Apr/Jun 1898)
sp:;Elizabeth;b.Abt 1830;m.10 Dec 1854;d.1907)
3.;Isabella;Wigham;b.Abt 1856)
4.;Margaret;Ann Hughes;b.Abt 1893)
4.;Harriett;Hughes;b.Abt 1897)
sp:;John;Lawson;m.Jan/Mar 1875)
4.;Elizabeth;Lawson;b.Abt 1876)
4.;Sarah;J. Lawson;b.Abt 1877)
3.;Sarah;Jane Wigham;b.Oct/Dec 1858;d.1941)
sp:;George;William Stoker;b.Abt 1857;m.Jan/Mar 1876;d.1891/1901)
4.;Elizabeth;Stoker;b.Abt 1878)
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

[^m\.] (or [^m.] ) matches any character, including a newline, that isn't m or . (dot). That's why the matches can extend over newlines.

If you really need to capture the text matching the parenthesised parts of your regex then
([^m.\r\n]*)m\.([^;\r\n]*);(.*)
or
([^m.\r\n]*)m\.(.*?);(.*)
might do the trick. Otherwise a simple
m\..*;
might find the lines you're interested in.
rsborland
Posts: 2
Joined: Sat Jul 13, 2013 5:42 pm
Location: United States

Post by rsborland »

Thanks for the help, Ben!

Can I ask - why use both "\r" and "\n"? Both are listed as matching "any line ending character sequence " - is there something unwritten about their combination?
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

In a character set ([...]) \r means just a carriage return and \n means just a line feed. If your file has unix line endings you can leave out the \r.

This should be made clearer in the help.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

In fact you can leave out the \r even if your file has Windows line endings, as a \r never occurs without a \n.
Post Reply