Thread: regex.h

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    86

    regex.h

    I need to find a method in c++ to split a c++ string based on the occurence of a regular expression.

    In case that's confusing;

    My goal is to set up a vector <string> to recieve the value. the value is returned based on a regular expression. If the string were (quotes for clarity) "hello, world" this supposed method would return {"hello,","world"} if the regular expression given were a space.

    I've tried calling this supposed method (split) from the libraries string and regex.h by saying
    Code:
    string str=txt.split(",")
    or something of that nature.

    anyone know of such a method?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    cstring's strtok() can do that, but your regular expression would have to be a single character. You'd just need to access the C-style string contained in your string object. If your needs get too specific, you could always write your own function

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The Boost libraries contain both simple string tokenizing and full-blown regular expression matching.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    wats the syntax for strtok?

  5. #5

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Regular Expressions (regex.h) small problem
    By _Marcel_ in forum C Programming
    Replies: 0
    Last Post: 03-31-2009, 05:13 AM