473,511 Members | 10,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the preg for capitals in a word to be replaced by that word preceded by a space

hi all

what is the preg for capitals in a word to be replaced by that word
preceded by a space?

i need to be able to do this in preg:

thisWord := this Word
AnotherExample := Another Example

strings with capitals sorrounded by other chars need to have a space
inserted before the capital.

Jan 10 '07 #1
5 1384
$string = '
thisSeems
toWork
prettyWell';

echo preg_replace('/([a-z])([A-Z])/',"$1 $2",$string);

Jan 10 '07 #2
zorro wrote:
$string = '
thisSeems
toWork
prettyWell';

echo preg_replace('/([a-z])([A-Z])/',"$1 $2",$string);
IWantIt2Work =IWant It2Work

;-)

Try:

echo preg_replace('/(.)([A-Z])/', "$1 $2", $string);

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 11 '07 #3

Toby Inkster wrote:
echo preg_replace('/(.)([A-Z])/', "$1 $2", $string);
This won't always work either, although I haven't tested it.
If (.) can be any character then " Word" will be replaced by " Word"
(2 spaces).

Maybe this:
preg_replace('/(\w)([A-Z])/', "$1 $2", $string);

Jan 11 '07 #4

zorro wrote:
Maybe this:
preg_replace('/(\w)([A-Z])/', "$1 $2", $string);
That's no good because it would transform WORD into WO RD...

Maybe this then:
preg_replace('/([a-z\d])([A-Z])/', "$1 $2", $string);

Jan 11 '07 #5
zorro wrote:
zorro wrote:
>preg_replace('/(\w)([A-Z])/', "$1 $2", $string);

That's no good because it would transform WORD into WO RD...
Into 'W OR D' actually. But then again, the OP never specified what he
wanted to happen when multiple uppercase letters appear consecutively.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2828
by: Daniel Kończyk | last post by:
I can't fing a way, to match any characters except the phrase 'foo'. Using + matches any character except a, b or c, but I need to not match 'foo', because f is ok, o is ok, but foo - 3 letters at...
3
4313
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str'...
4
3224
by: Margaret MacDonald | last post by:
I'm trying to write a filter that will ignore text of the form '\_foo\_' while filtering text of the form '_foo_'. In other words, a backslash is meant to protect against the operation of this...
18
21701
by: William Payne | last post by:
Hello, I need to write a program that opens a text file and scans the entire file for a specific line and when that line is found, a particular word on that line is to be replaced. The new word is...
2
1000
by: Connor T | last post by:
Hi, I followed this guide on msdn: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2k3ta/html/odc_VBNETcallsVBA.asp And have suceeded in launching word, and displaying...
2
1921
by: teo | last post by:
match word with interpunctuation Hallo, I need to build a regular expression able to match a specified word, preceded and followed by few chars (mainly interpunctuation) Below the code. ...
7
1382
by: Xah Lee | last post by:
I had a idea today. I wanted to know what are the top most frequently used functions in the emacs lisp language. I thought i can write a quick script that go thru all the elisp library locations...
0
996
by: Itanium | last post by:
Hi all. I need to recognize some special keywords in my app. I usually accomplish this task with a regex construction like this… \bkeyword\b …that means “match the keyword if it is preceded...
209
8575
by: arnuld | last post by:
I searched the c.l.c archives provided by Google as Google Groups with "word input" as the key words and did not come up with anything good. C++ has std::string for taking a word as input from...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.