#1
  1. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,134
    Rep Power
    601

    Remove All Characters until . space is found


    I have a string that is preceded with an arbitrary number of numeric characters followed by a dot (.) and a space ( ). I need an expression for perl to remove that and am not a regex expert. This is what I came up with that produces a unintended interpolation error.
    Code:
    $string=~s/$\. //;
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. Subconscious Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,533
    Rep Power
    9565
    Remove which part? Your title suggests the stuff before the period, your description just says "that", and your code suggests it's removing the period and space.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,134
    Rep Power
    601
    Sorry. Remove everything before and including dot space. However, I think I figured it out.
    Code:
     $string=~s/([0-9])*\. //;
    Probably not the best way but it seems to work as long as the characters preceding the dot space are always numeric.
    Last edited by gw1500se; August 17th, 2015 at 03:48 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. Subconscious Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,533
    Rep Power
    9565
    That'll be fine. It'll search anywhere in the string, though, not just at the beginning. Now that may not be a problem for you, but if it is,

    Use the ^ anchor for the beginning of the string. If the string has multiple lines in it and you want to check the beginning of a line, use the /m flag. And maybe /g if you need to remove more than one instance of this stuff.
    Code:
    $string =~ s/^[0-9]*\. //;
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,134
    Rep Power
    601
    Better yet. Thanks.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo