Results 1 to 2 of 2

Thread: Regular Expressions in JavaScript

  1. #1
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    46
    Thanked 1 Time in 1 Post

    Default Regular Expressions in JavaScript

    Hello,

    I'm horrible with regular expressions as was hoping that someone would be able to help me create the RegEx pattern I need to accomplish some basic data extraction.

    I have a url in following format:

    Code:
    http://www.example.com/xxx/yyy/index.php?/zzz/aaa/###
    I just need the last number (highlighted above). The number itself can be any number of digits long and it's always preceded by a backslash.

    Does anyone know a right RegEx pattern to accomplish what I want?

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here:
    Code:
    <script type="text/javascript">
    var site = "http://www.example.com/xxx/yyy/index.php?/zzz/aaa/###";
    
    
    var site_arr = site.split("/");
    alert(site_arr[site_arr.length-1]);  
    </script>
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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