Regular Expression

This is a discussion on Regular Expression within the Tech Board forums, part of the Community Boards category; Am very new on this, but will ask questions to confirm what am learning example .. 1. [abc] does this ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Regular Expression

    Am very new on this, but will ask questions to confirm what am learning

    example ..

    1. [abc] does this mean a or b or c, or does it mean definitely abc .. Here's an example

    ez*.[ch]pp would this match anything starting with ez with an extension chpp or cpp/hpp?

    that's my first question

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Your faith that C++ people would know something -- anything -- about regular expressions is touching.

    Anyway, if you wanted to match "abc", you'd just type "abc" so obviously the brackets mean something. In all regexes that I know of, [abc] means one (and exactly one) of the elements in the brackets.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by tabstop View Post
    Your faith that C++ people would know something -- anything -- about regular expressions is touching.
    the brackets.
    Hahah! You made have brought a smile to my face, tabstop.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Oh, and you can google "regular expressions" and find just all sorts of tutorials etc.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by master5001 View Post
    Hahah! You made have brought a smile to my face, tabstop.
    He's very touchy with his touching remarks, am touched! ...

    Here's the next one, i just made this up so could be completely out of the way

    Code:
    "^(0[1234])+1[\s]([\d]{3}[\s]([\d]{4})$"
    
    // I aim to match a number such as "011 234 5678"
    
    011 = ^(0[1234])+1   // can also be 021/031/041
    
     234 = [\s]([\d]{3}     // notice a space infront
    
     5678 = [\s]([\d]{4})$
    Please am not trying test your knowledge, am desperate ... thanx

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by tabstop View Post
    Oh, and you can google "regular expressions" and find just all sorts of tutorials etc.
    Yes, but then one needs a bit of a test after reading!!!

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The 0[1234] can be repeated, so 01011 234 5678 also matches. If that's what you want, then hey.

    Edit: And upon re-review, I think you're missing a parenthesis that I automatically fixed when I read it.
    Last edited by tabstop; 09-02-2008 at 03:37 PM.

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Moved to Tech as this is better suited for RegEx stuff

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
    [\s]([\d]{4})$
    There's no need to surround single characters (or escape sequences) with square brackets; this does exactly the same thing.
    Code:
    \s(\d{4})$
    (Although I think the curly-brace-repetition is not part of the POSIX regular expression standard. It may be part of extended POSIX regex, though, and it's definitely in Perl.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  3. Regular Expression
    By tintifaxe in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2006, 08:16 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. Regular Expression Troubles
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2002, 05:21 PM

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