How to find a specific number of occurrences of a character

General questions about using TextPad

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

Post Reply
jimbo2112
Posts: 7
Joined: Mon Oct 29, 2007 6:19 pm

How to find a specific number of occurrences of a character

Post by jimbo2112 »

Hi All,

Searched to no avail on this one. As I understand, the reg ex for catching one occurrence of a character you would search with {1}. TextPad does not like this. My aim is to find things like this:

What a BigProblem this is

Using

\([a-z]{1}\)\([A-Z]{1}\)

and replace with

\1 \2

so, the result would be:

What a Big Problem this is

Any suggestions on how to restrict the search length to 1 character?

PS I have switched on case sensitivety!

Many thanks

Jimbo
jimbo2112
Posts: 7
Joined: Mon Oct 29, 2007 6:19 pm

Post by jimbo2112 »

Panic over. I had the correct reg-ex in the first place, but for some reason the POSIX option was switched off in preferences. In case anyone was wondering, the actual search string with POSIX in place would not need the `\` before the `(`:

([a-z]{1})([A-Z]{1})

Thanks anyways!
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You were mixing Posix and non-Posix syntax.

Anyway, x{1} is equivalent to x , so the braces are unnecessary.

So this is all you need:
Find what: ([a-z])([A-Z])
Replace with: \1 \2

[X] Regular expression
jimbo2112
Posts: 7
Joined: Mon Oct 29, 2007 6:19 pm

Post by jimbo2112 »

Indeed I was in the first post.

So in POSIX, the default match value is 1?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

In every style of regex (there are many), x matches a single x.
jimbo2112
Posts: 7
Joined: Mon Oct 29, 2007 6:19 pm

Post by jimbo2112 »

Cheers Ben, Handy to know.
Post Reply