473,670 Members | 2,343 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 1390
$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
2837
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 once not Any clue? Thanks -- Daniel Kończyk
3
4317
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' which may contain new lines and will contain html code, IN this string any "words" that begin with an underscore I want to replace with a given word. A word here being a group of chars preceded by a space or null (start of line) and closed by a...
4
3239
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 particular filter. To detect the leading backslash once I find the underscore, I've been trying to use a 'negative lookbehind' in preg_replace. It seems a perfect use for it: if we find an under but it was preceded by a backslash, don't...
18
21811
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 given as an argument to the program. I wrote a small test program that doesn't work because strcmp() fails to find a matching line. Here's the code: #include <stdio.h> #include <string.h> int main(int argc, char** argv)
2
1003
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 data from my database. However what I can't figure out is how to setup a data source in word, and insert fields into my pre-written form from the database. I'm pretty sure
2
1927
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
1393
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 and get a word-frequency report i want. I started with a simple program: http://xahlee.org/p/titus/count_word_frequency.py and applied it to a Shakespeare text. Here's a sample result:
0
1005
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 and succeeded by a non-alphanumeric character only”. This time I need to NOT allow a keyword to be matched if it is preceded or succeeded by a $ character, but unfortunately the damned regex engine considers the $ a non-alphanumeric character, so...
209
8725
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 stdin. C takes input in 2 ways: 1) as a character, etchar() 2) as a whole line, fgets()
0
8469
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8814
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5684
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2042
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1794
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.