MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Sigil (https://www.mobileread.com/forums/forumdisplay.php?f=203)
-   -   lower case to capital (https://www.mobileread.com/forums/showthread.php?t=122670)

tscamera 02-22-2011 03:52 PM

lower case to capital via regex
 
hi,
does anybody know, how i can change lower case to capital.
(i mean whole words)
via
regex.

:bulb2:

tscamera 02-23-2011 04:30 AM

coming closer
 
....while browsing through the regex references i found the search string:

([a-zA-Z])*-

using the hyphen or any other (i.e. space) as the delimiter.

BUT how to replace?

please help!

Perkin 02-23-2011 05:01 AM

I'm pretty sure you cant batch replace with capitals.

Depending on how many need capitalizing, you've got two options.

Loop through each lowercase letter and replace with it's capital
Search 'a' -> Replace 'A'
Search 'b' -> Replace 'B'
etc. (match case)

Or
Copy all the text into a text editor of your choice, select a section that you want capitalized and in menus/toolbar 'Change to UPPERCASE'.
(Will only work if your editor has that ability)

Depending on how much you want changed and a couple of other factors, the Search/Replace will probably be easier, if not monotonous.

cybmole 02-23-2011 06:10 AM

css syntax has something called text-transform but I've not messed with it
http://www.w3schools.com/css/pr_text_text-transform.asp

tscamera 02-23-2011 07:42 AM

in general: is there a way to capitalize (+visversa) with regex?
 
thanks so far.
but i'm definitly searching for a REGEX solution.
not just for SIGILs find/replace, also for other engines/progs with replace option.
so, in general: is there a way to capitalize (+visversa) with regex?

as i said: ([a-zA-Z])*-
will find whole words ending with a choosen delimiter.
i need the syntax for the replace field.

Jellby 02-23-2011 08:04 AM

Quote:

Originally Posted by cybmole (Post 1410948)
css syntax has something called text-transform but I've not messed with it
http://www.w3schools.com/css/pr_text_text-transform.asp

And it's not in the ePUB-supported subset.

Perkin 02-23-2011 10:04 AM

You can't replace with uppercased-match with regex.

goranjan 03-18-2012 05:00 PM

I think the answer is is Python
 
I assume you guys are talking about the regex search and replace while doing a conversion.

I am hitting the same problem - except in my case I am matching on text which is in bold, and I want to make it upper case.

If this Search/Replace is based on Python, why can't we use the Python function:

string.upper()

in my case it would be (\1).upper(), since \1 is the match group from my regex.

Thanks,
Goran

DiapDealer 03-18-2012 05:51 PM

A little over a year later but... with PCRE (that Sigil uses) anyway...

Find: \b(word)\b
Replace with: \U\1\E

Turns "word" into "WORD"

Find: \b(word)\b
Replace with: \u\1

Turns "word" into "Word"

Perkin 03-18-2012 06:55 PM

@DiapDealer Nice, but can you also change upper to lower case

e.g Chapter ONE -> Chapter One

If it's lower to upper as wanted in topic we can do
Chapter one -> Chapter One

Search
Code:

(Chapter )(.+?\b)
Replace
Code:

\1\u\2
So what would the replace be for this if possible?
Code:

Chapter ONE
Desired result would be
Code:

Chapter One
(I'd expect same or similar search as above)

EDIT:
Found a solution.

Search
Code:

(Chapter )(.)(.+?\b)
Replace
Code:

\1\u\2\L\3\E

DiapDealer 03-18-2012 07:50 PM

I see you already discovered a solution while I was typing, so I modified it so it will detect and fix Chapter TWENty-oNE as well. :D

Code:

(Chapter )(\w)(.+?\b)
Replace:

Code:

\1\u\2\L\3\E
But that won't help when you get as high as "Chapter TWENTY-ONE," soooo.....

Code:

(Chapter )(\w)(.+?\b)((-)(\w)(.+?\b))?
Replace:

Code:

\1\u\2\L\3\E\5\u\6\L\7\E
Should straighten up any capitalization issues of the part that follows "Chapter ", as long as it maintains a standard "word" or "word-word" convention)

"Chapter ONe" will become "Chapter One" and "Chapter THIRTY-two" will become "Chapter Thirty-Two" :D

Perkin 03-18-2012 10:06 PM

Great, that also gives everyone a rough idea of how to adapt either version for other uses.

Thanks.

DiapDealer 03-18-2012 11:54 PM

Quote:

Great, that also gives everyone a rough idea of how to adapt either version for other uses.
Just in case it's unclear for any following along:

\u Uppercase the next character
\l Lowercase next character
\U Uppercase until \E
\L Lowercase until \E
\E End case modification


All times are GMT -4. The time now is 07:02 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.