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
    Master Coder
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    5,419
    Thanks
    26
    Thanked 748 Times in 746 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.

    Because I love FLEXBOX and tired of waiting: http://davidwalsh.name/goodbye-vendor-prefixes

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

  • #4
    Master Coder
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    5,419
    Thanks
    26
    Thanked 748 Times in 746 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.

    Because I love FLEXBOX and tired of waiting: http://davidwalsh.name/goodbye-vendor-prefixes

  • 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,637
    Thanks
    208
    Thanked 2,593 Times in 2,571 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 05: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
    •