473,802 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

split camelcase string into array of words words

Hi,

I'm looking for an optimal javascript function to split a camelcase
string and return an array.

I suppose one could loop through the string, check if character is
uppercase and start building a new word to add to the array but that
seems incredibly wasteful. must be some easy way to do it.
Thanks.

Jul 21 '06
10 11954
JRS: In article <rNcwg.15164$Nv .12737@fed1read 10>, dated Fri, 21 Jul
2006 15:44:40 remote, seen in news:comp.lang. javascript, Jeremy
<je****@pinacol .composted :
>Dr John Stockton wrote:
>>
But this : "camelCaseStrin g".match(/(\b|[A-Z])[a-z]*/g)
returns ['camel','Case', 'String']

And this : "camelCaseSTRin g".match(/(\b|[A-Z]+)[a-z]*/g)
returns ['camel','Case', 'STRing']

What does \b do? Never seen that before.

\b Matches a word boundary, that is, the position between a word and a
space. For example, 'er\b' matches the 'er' in "never" but not the 'er'
in "verb".

\b Matches a word boundary, such as a space. (Not to be confused with
[\b].) For example, /\bn\w/ matches the 'no' in "noonday";/\wy\b/
matches the 'ly' in "possibly yesterday."
Note that the documentations quoted above are inadequate, not really
defining "word boundary".

A Web search should find lists of RegExp parts.

<FAQENTRYRegExp s are often asked about, but the FAQ is little help
(two links in 4.16); AFAIK, the Notes do not cover them (IMHO, the FAQ
should have a link to EACH of the Motes).

Try the links in <URL:http://www.merlyn.demo n.co.uk/js-valid.htm>.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 22 '06 #11

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

Similar topics

5
31182
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it will split myString up using the delimiter of 1 space so that
2
1771
by: John Benson | last post by:
I never cared for CamelCase because a lot of words in English are compounds, and remembering the right CamelCase rendition of them gets difficult. For example, an object attribute named HaveAMerryChristmas isn't too hard, but what about deciding between HaveAGoodWeekend
5
57205
by: Vamsi | last post by:
Hi, I am trying a basic opearation of splitting a multiline value to an array of single lines(Actually making Address into AddressLine1, AddressLine2). I used Environment.NewLine in split, I could get only 1st line, but it is not returning 2nd line. here's code: string address = null; string ssep = Environment.NewLine; char sep = ssep.ToCharArray();
3
2103
by: John Salerno | last post by:
This is an example in the book I'm reading: string fullName = " Edward C Koop "; fullName = fullName.Trim(); string names = fullName.Split(' '); string firstName = names; // Edward Two questions about this: 1. Why do you use single quotes with Split() instead of double? Is this
8
14204
by: Dave | last post by:
Greetings, Is there a way I can split a string into an array on a space OR a carriage return? What would the code look like for this? Thanks, -Dave
3
9671
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3... field1...field2...field3...
6
2172
by: Saurabh | last post by:
Hi everyone, I am looking for some expert advise to get me out of trouble. I am looking for a solution in C# which will allow me to split the below string in the format provided. The String.Split() allows only a single char as a delimiter.So I cannot use that as well. Original String "*** MASTER (Supervisor) *** September 23, 1997 at 3:22pm \r\nThis is the first line of text. There will be many more beneath this on so look...
2
5892
by: pmwhelan | last post by:
Hi I want to split a string into an array and treat quoted phrases as words. I was splitting on a space which worked fine. char delimiterChars = {' '}; string arrValues = searchText.Split(delimiterChars); This would split a sentence ... this is a test
3
186
by: shapper | last post by:
Hello, I have a string as follows: string text = "Paris, New York , London,Lisbon,Oslo, Chicago "; I need to get all words with no commas or spaces: "Paris", "New", "York", "London", "Lisbon", "Oslo", "Chicago" I am using (I think it is ok):
0
9562
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10063
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
9114
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
7598
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
6838
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
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.