473,666 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple (regex?) string manipulation

Blonde moment...

Before I try and do it a harder way, can anybody remind me how to get
the desired from the following? I simply want to split
"aTypicalCamelC asePropertyName " into a "a Typical Camel Case Property
Name" (fully expanding upper-case blocks as the simplest answer to the
ambiguity)

Console.WriteLi ne(Regex.Replac e(
@"testInputOfWh atIWantUPPERS",
@"([a-zA-Z])([A-Z])",
@"$1 $2"));

I want: "test Input Of What I Want U P P E R S"
I currently get: "test Input Of What IWant UP PE RS" - i.e. the upper-
case is getting consumed each time.

Any offers?

Marc

Aug 15 '07 #1
2 1908
Hello Marc,
Blonde moment...

Before I try and do it a harder way, can anybody remind me how to get
the desired from the following? I simply want to split
"aTypicalCamelC asePropertyName " into a "a Typical Camel Case Property
Name" (fully expanding upper-case blocks as the simplest answer to the
ambiguity)

Console.WriteLi ne(Regex.Replac e(
@"testInputOfWh atIWantUPPERS",
@"([a-zA-Z])([A-Z])",
@"$1 $2"));
I want: "test Input Of What I Want U P P E R S"
I currently get: "test Input Of What IWant UP PE RS" - i.e. the upper-
case is getting consumed each time.
Any offers?

Marc
Make the first group a Look behind, so that is is not part of the match.
Then only insert a space before the found character like so:
Console.WriteLi ne(Regex.Replac e(
@"testInputOfWh atIWantUPPERS",
@"(?<=[a-zA-Z])([A-Z])",
@" $1"));

--
Jesse Houwing
jesse.houwing at sogeti.nl
Aug 15 '07 #2
Perfect; much obliged

Marc

Aug 15 '07 #3

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

Similar topics

3
2240
by: Chris | last post by:
I need to write a function that will remove a specified parameter from a URL. For example: removeParam("param1", "http://mysite.com/mypage.htm?param1=1&param2=2"); would return: "http://mysite.com/mypage.htm?param2=2" I'm thinking that string.replace(/regex/, ""); would do the trick, but how
4
4265
by: Tom | last post by:
I have string that is 2.5 million bytes long. I tried using Regular Expressions to look for patterns and replace the pattern found with a pre-defined text. This works great on some computers but on some others (win 2K server 1gig of ram) it times out! So I am looking for an alternative method as I've been told Regular Expressions are expensive. Here is my pattern;
4
4540
by: Brian Henry | last post by:
I have phone numbers like this in a data table 123-435-1234 1231231234 432.234.2321 they all have different formatting, what I want to do is get them all formatted like this (123) 123-1234
4
1914
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: cond(c,a,b)
1
4210
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD: (there is a WORD in ( my string WORD )) and * WORD * to (find WORD) and * WORD * Should give me the to word between star (star ar not part of string)
6
3721
by: PaulM | last post by:
...all but the first x chars in a string of arbitrary length? Apologies if this is the wrong forum; I wasn't sure the best place to post about Regex. Background: I am new to Regex for pattern matching. I have started using Yahoo Pipes to manipulate RSS feeds. Yahoo Pipes includes a regex gadget to do string manipulation, but no "stateful" programming. My goal is to truncate a string of arbitrary length to a fixed length (of, say, the...
15
50224
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
16
2244
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string) pattern search functions. Where performance is an issue you can alway write your own specialized routine of course. However, for the occasional pattern search where performance isn't an issue, would most seasoned .NET developers rely on "Regex" and...
15
5992
by: nagar | last post by:
I need to split a string whenever a separator string is present (lets sey #Key(val) where val is a variable) and rejoin it in the proper order after doing some processing. Is there a way to use the Regex.Split function to split the string whenever the #Key(val) occurrs but that keeps the #Key(val) occurrences to that I can reconstruct the final string after doing certain operations on each token (I need to basically convert each string...
0
8448
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
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
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...
0
8640
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
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
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
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.