
-----------------------------------
Martin
Thu Nov 25, 2004 5:23 pm

Regex, breaking apart a string.
-----------------------------------
Suppose I had a string of characters and a dynamic array. Would there be any way, with regex, to break the string up into substrings seperated by specified characters?

I guess the best example of this would be breaking up a sentence into words.

-----------------------------------
wtd
Thu Nov 25, 2004 7:12 pm

Re: Regex, breaking apart a string.
-----------------------------------
Suppose I had a string of characters and a dynamic array. Would there be any way, with regex, to break the string up into substrings seperated by specified characters?

I guess the best example of this would be breaking up a sentence into words.

Well, basically, words are composed of letters, and possibly apostrophes.  So we want to split on anything that isn't one of those characters.

For this, we can use a negative set.

[^a-zA-Z']

Now, in Ruby, for instance:

irb(main):004:0> "hello world".split /[^a-zA-Z']/i
=> ["hello", "world"]
irb(main):005:0>

-----------------------------------
rizzix
Thu Nov 25, 2004 9:18 pm

Re: Regex, breaking apart a string.
-----------------------------------
Suppose I had a string of characters and a dynamic array. Would there be any way, with regex, to break the string up into substrings seperated by specified characters?

I guess the best example of this would be breaking up a sentence into words.

yes u can and in java its a matter of String[] results = the_string.split("/"); where / is the separating delimiter.

-----------------------------------
Martin
Thu Nov 25, 2004 11:08 pm


-----------------------------------
Oh, perfect. Is there a way to do it in C++ though?

-----------------------------------
wtd
Thu Nov 25, 2004 11:09 pm


-----------------------------------
Oh, perfect. Is there a way to do it in C++ though?

There is no standard regular expression library for C++.  It is being included in the next C++ standard, from what I hear.

-----------------------------------
Martin
Thu Nov 25, 2004 11:43 pm


-----------------------------------
Excellent.

I have been reading your tutorials, wtd, I just don't reply because I don't want to mess up the order :p

-----------------------------------
md
Thu Nov 25, 2004 11:58 pm


-----------------------------------
if you need a good string class martin I've written one you can use. In fact if you ever looked at the project you would see it...

[edit] anyone else can get it from http://svn.nxor.org/ tis somewhere in hte BF-F project

[edit #2] tis in BF-f/src/cString there is a header file and a source file

-----------------------------------
wtd
Fri Nov 26, 2004 12:05 am


-----------------------------------
if you need a good string class martin I've written one you can use. In fact if you ever looked at the project you would see it...

I don't see how this is better than std::string.
