what's this thing called: [^,]

This is a discussion on what's this thing called: [^,] within the C Programming forums, part of the General Programming Boards category; I've seen variants of this thing in other threads ie. [A-z 0-9]. I've even attempted to use [^,] once(unsucessfully), without ...

  1. #1
    In my head happyclown's Avatar
    Join Date
    Dec 2008
    Location
    In my head
    Posts
    391

    what's this thing called: [^,]

    I've seen variants of this thing in other threads ie. [A-z 0-9]. I've even attempted to use [^,] once(unsucessfully), without really knowing what it does.

    What is it called?

    If you use [^,] in a scanf statement the comma will be ignored by scanf?

    Does anyone have a link on how to use it(and the context in which it is used)?

    Thanks in advance.
    OS: Linux Mint 13(Maya) LTS 64 bit.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    In a scanf format string, it's called a scanset. You should look up scanf in any reputable source (such as say "man scanf") to find out more information.

    In your case [^,] matches everything except a comma, so it would probably be used in parsing comma-separated values.

  3. #3
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    The ^ is called a carat incidently if thats what you meant.

    Incidently does [^abcdef] mean everything apart from abcdef, I think it does.
    Not 100% though. Or would it be ^[abcdef]? I think the latter.

    They are used not just in programming C, unix/linux used them too and other programs as well.
    http://www.regular-expressions.info/quickstart.html

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,821
    Quote Originally Posted by esbo
    Incidently does [^abcdef] mean everything apart from abcdef, I think it does.
    Yes, it matches a character not among those listed.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by laserlight View Post
    Yes, it matches a character not among those listed.

    So not ^[abcdef] then?
    I guess not it did look wrong.

    [^abcdef]

    I used to be really good at them in when I used to use the vi editor but I have forgotten
    most of it now as I no longer use it.

    Actually I just reallised notepad++ does allow you to use them so may I should relearn them. They can save you a lot of work. For example swopping two columns of names
    eg

    Fred Smith
    Bill Blogs
    Tom Brown

    Takes ages to do manually if you have 100's of lines.

    I think it was somoething like
    Code:
    \{[a-Z]\} {\{[a-Z]\}/\{2\}\{1\}/
    That's probably wrong though there might be a bit more to it but basically it capures the data and you can specify the column by number.

    Or maybe it was more like this:-
    Code:
    \{[a-Z]\} {\{[a-Z]\}/\2 \1/
    Anyway I can have a play around with it and see what happens

  6. #6
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Don't think I can do it in notepad but I think it was

    Code:
    :%s/\{*[a-Z]\} {\{*[a-Z]\}/\2 \1/
    In vi. I think.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. constructor called on statically allocated arrays?
    By cyberfish in forum C++ Programming
    Replies: 9
    Last Post: 03-05-2008, 04:44 PM
  2. How constructors are called in c++ (inheritance)
    By Spirytus in forum C++ Programming
    Replies: 3
    Last Post: 01-08-2007, 05:18 PM
  3. Replies: 6
    Last Post: 04-21-2006, 08:49 PM
  4. PlaySound doesn't play when called!
    By Queatrix in forum Windows Programming
    Replies: 7
    Last Post: 03-03-2006, 07:02 PM
  5. How is main() called?
    By anoopks in forum C Programming
    Replies: 13
    Last Post: 11-07-2004, 09:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21