Thread: regex help

  1. #1
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416

    regex help

    since I'm completely at a loss with regex [ yup, I rarely do any shell scripting so I have never actually needed to use one before ]

    does anyone know what the regex would be to append 000 to any file in the searched folder that has an extention?

    By extention, I mean any file that has a . in the name.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So you want this in say a bash script and not a C or C++ program?

    > does anyone know what the regex would be to append 000 to any file
    Is this appended to the file, or appended to the filename ( foo.c -> foo.c000 )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    bash, perl, python, php..
    or any other valid scripting language for *x
    which is also c and c++.

    appended to the filename. foo.bar >> foo.bar000
    [ zero not capitol o .. I do miss the old differentiated zero of system fonts ]

    it's not the entire script or program, just the regex that would do the scan and exchange.

    I know that perl or bash is much simpler than c or c++ for this. my neighbour actually asked me how and I just don't know regex use to show him.
    Last edited by Jaqui; 10-13-2006 at 06:34 AM.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Regex doesn't do that. You want Bash replacement expressions. Something like $(listing#.000) or something - I never remember the syntax. It's curly braces, I know that. How do I trick the code tags script? The new one isn't fooled by a pair of code tags somewhere else in the post.
    info bash
    should provide more information.
    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

  5. #5
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    regular expressions won't allow you to scan for a specific item then make a change to it ?

    someone better tell the apache mod_rewrite developers that, since that is exactly what it does.

    and all the spam detection software, that uses regex to perform a scan then trigger an action.

    I know the regex won't make thealteration, it is only the scanning criteria.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Well, you made my point.

    And of course, regex for searching for a single dot is quite some overkill.
    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

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Regex?

    Just use bash(1)'s for:

    Code:
    $ for f in *.*; do mv $f ${f}000; done
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  8. #8
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Regex can look VERY cryptic, but once you learn it it is amazing .

    I agree that it is overkill for this, but do some parsers in Perl and you will learn to love Regex. It is awesome how easy it makes some things.

  9. #9
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    zx-1, thanks, I don't do a lot of shell scripting work.

    Wraithan,

    I know, it took me 3 hours to fully understand a rewrite rule regex. reading the docs on regex and having the rule there to dissect it with the docs. I still don't understand regex well enough to trust my own coding on it. Until I do, I'll not hesitate to ask for help when I need regex.

    It always looks cryptic, but it allows for extremely clean and elegant code that does the task perfectly and quickly. A single iteration through something rather than multiple iterations.
    Quote Originally Posted by Jeff Henager
    If the average user can put a CD in and boot the system and follow the prompts, he can install and use Linux. If he can't do that simple task, he doesn't need to be around technology.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with Boost Regex in Eclipse CDT
    By Hunter0000 in forum C++ Programming
    Replies: 4
    Last Post: 01-13-2010, 12:22 PM
  2. Regex for path parsing
    By AngKar in forum C# Programming
    Replies: 4
    Last Post: 06-09-2006, 12:30 PM
  3. My own regex...............class?
    By misplaced in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2005, 09:18 AM
  4. <regex.h> regex syntax in C
    By battersausage in forum C Programming
    Replies: 7
    Last Post: 03-24-2004, 01:35 PM
  5. How is regex used?
    By Strider in forum C++ Programming
    Replies: 0
    Last Post: 12-14-2001, 08:15 AM