473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
"aTypicalCamelCasePropertyName" into a "a Typical Camel Case Property
Name" (fully expanding upper-case blocks as the simplest answer to the
ambiguity)

Console.WriteLine(Regex.Replace(
@"testInputOfWhatIWantUPPERS",
@"([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 1894
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
"aTypicalCamelCasePropertyName" into a "a Typical Camel Case Property
Name" (fully expanding upper-case blocks as the simplest answer to the
ambiguity)

Console.WriteLine(Regex.Replace(
@"testInputOfWhatIWantUPPERS",
@"([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.WriteLine(Regex.Replace(
@"testInputOfWhatIWantUPPERS",
@"(?<=[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
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: ...
4
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...
4
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
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: ...
1
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:...
6
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...
15
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
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)...
15
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.