Replace Space between number and small alpha character

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Replace Space between number and small alpha character

Post by gerd »

TextPipe is great. I have just touched the surface but it can really save hours and days of work. Therefore, I have gone through some filters and threads here in the forum to understand more of it.

May I ask one more thing which I cannot get working.
I have the following text (example):
§ 10 a, § 5 b, § 266 c, § 1200 f
My target:
If a string starts with "§" followed by one or two spaces, thereafter comes a digit (see example), thereafter a space and thereafter in some cases one small letter (case sensitivity is here important).

If this is the case I want to get the following output
§ 10a, § 5b, § 266c, § 1200f
but all other strings like
§ 10 A etc. should not be changed. the rule reads as follows:
§ (one or two) spaces (digit) space small letter (just one character)

I did some trial and error like
Find Pattern (perl-style)
§ ([0-9])[\s ]([a-z])
and Replace with
§ $1$2
But all trials failed. A hint or the code would be grat.
Thanks
gerd
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace Space between number and small alpha character

Post by DataMystic Support »

You're very close Gerd.

§ ([0-9]+)[\s ]([a-z])
- you need one or more digits (hence the +)

and the replacement needs to be
§ $1$$2
to disambiguate
($1)($2) - the 2nd found pattern
from
($1)(2) - the number two.

You could also use an EasyPattern
§ (one or two) spaces (digit) space small letter (just one character)
becomes
§ [ 1..2 spaces, digit, space, lowercaseLetter ]
which we need to correct to
§ [ 1..2 spaces, 1+ digit, space, longest optional lowercaseLetter ]
and then finally
§ [ 1..2 spaces, capture(1+ digit), space, capture(longest optional lowercaseLetter) ]
gerd
Posts: 39
Joined: Wed Mar 12, 2008 10:52 pm

Re: Replace Space between number and small alpha character

Post by gerd »

Thanks,
the Easy Pattern does not work. I receive each time the hint
"Output file does not appear different from ..."
but the Perl pattern
§ ([0-9]+)[\s ]([a-z])
works as requested with one exemption
§ 10 aaa leads to § 10aaa as well but it should remain to § 10 aaa
Rule: Only if there is one small letter followed by a space after the number
Example:
§ 10 a Hello should become § 10a Hello
and
§ 10 aa Hello should not be changed
§ 10 A Hello should not be changed

I am still working with the manual and do some trial and error for ([a-z]) with {1} and so on to find out the pattern for just ONE small letter followed by a space. But so far my approaches do get me any further.
gerd
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace Space between number and small alpha character

Post by DataMystic Support »

Hi Gerd,

Because I can't easily show you a space, I've put the space into a character class here - same effect as just typing in a space.

Code: Select all

[a-z]{1}[ ]
But better yet - use this EasyPattern:

Code: Select all

§[ 1..2 spaces, capture(1+ digit), space, capture(longest optional lowercaseLetter), mustNotEndWith( lowercaseLetter) ]
Post Reply