Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    Remove characters before and including.....

    Hi ALL!

    If I have a variable and need to remove all characters before and including a "/" or "-" how can I do that?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,715
    Thanks
    25
    Thanked 660 Times in 659 Posts
    What language are you using. This is for DOM and JSON scripting.
    I would think setting the variable equal to '' (an empty string) would do the job.
    Would help if you gave us the string.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts
    Just plain old javascript

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,715
    Thanks
    25
    Thanked 660 Times in 659 Posts
    Still didn't tell us the chars needed to be removed or post the string, but this will only leave a string (str) with alphanumeric charaters:
    str = str.replace(/[^a-zA-Z 0-9]+/g,'');
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    nikko50 (05-01-2014)

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Quote Originally Posted by nikko50 View Post
    Hi ALL!

    If I have a variable and need to remove all characters before and including a "/" or "-" how can I do that?
    Code:
    var txt = "abc/123?xyz";
    txt = txt.replace(/(.*\/)|(.*-)/i,"");
    alert (txt);  // 123?xyz
    If you require a Javascript solution it would be best to post in the Javascript forum.
    Last edited by Philip M; 05-01-2014 at 06:56 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •