Find all occurrences

General questions about using TextPad

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

Post Reply
gcotterl
Posts: 252
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Find all occurrences

Post by gcotterl »

Is there way to find the number of times "are" occurs in this list:

are are thi
thi are are
are are are
are thi are
thi thi thi
thi thi are
are are thi

The result should be 12
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Search | Replace... (<F8>):
Find what: \bare\b
Replace with: are

[X] Regular expression

Replace All
The number of replacements is displyed in the status bar.

You can undo the replacement to keep your editing history in good order.
gcotterl
Posts: 252
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Post by gcotterl »

Thanks!
gcotterl
Posts: 252
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Post by gcotterl »

Is there way to find the number of times "goat" occurs in this list:

goat goat thi
thi goat goat
goat goat goat
goat thi goat
thi thi thi
thi thi goat
goat goat thi

The result should be 12
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Didn't I already answer that?
gcotterl
Posts: 252
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Post by gcotterl »

Yes.

It worked when the string is 'are' but not when the string is 'goat'

(The error says: "Invalid back reference: specified capturing group does not exist. The error occurred while parsing the regular expression:

'\g>>>HERE>>>oat\b'
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Not
\goat\b
but
\bgoat\b

\b matches a word boundary. It stops are maching in, for example, claret.
gcotterl
Posts: 252
Joined: Wed Mar 10, 2004 8:43 pm
Location: Riverside California USA

Post by gcotterl »

Thank you
User avatar
AmigoJack
Posts: 596
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

Alternatively use the "Mark all" button, which will also print in the status bar how often it matched.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

No it doesn't. It shows how many lines were marked, not how many matches were found, despite its indicating otherwise.
User avatar
AmigoJack
Posts: 596
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

You are right, didn't know this. Looking into the manual (speak: help file) however it's already explained as "marks every line" instead of every "occurance". This should be fixed (status bar should also use the word "line") and enhanced (another button called "count matches").
Post Reply