Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8890197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:26:44+00:00 2026-06-14T22:26:44+00:00

I want to map what is in the location hash to a string. The

  • 0

I want to map what is in the location hash to a string. The mapping has to be based on a pattern below (:Placeholder would be arbitrary numbers, maybe RegEx?). What is the best way to handle this in a function?

    'news/:NewsID/dup' => 'newsDuplicate',
    'news/:NewsID' => 'newsDetail',
    'news/:NewsID/authors' => 'authorsList',
    'news/:NewsID/authors/' => 'authorsList',
    'news/:NewsID/authors/create' => 'authorsCreate',
    'news/:NewsID/authors/:AuthorID' => 'authorDetail',
    'news/:NewsID/authors/:AuthorID/orders' => 'orders',
    'news/:NewsID/authors/:AuthorID/workflow' => 'workflow',
    'news/:NewsID/authors/:AuthorID/tags' => 'tags'

I am trying to highlight the correct button in a navigation and wanted a function like handleNav() which would highlight the right button based on the pattern.

For example, when at http://mydomain.com#!news/123/authors/987, then I can do something like this:

function handleNav() {
  var current = ?? //get mapped string above
  $('button.' + current).addClass('active').siblings().removeClass('active');
}

How do I get the “current” variable above based on the mapping? Not sure if a bunch of if-else statements would be the best way and I do not know much regex. Thanks for any help or insight.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:26:45+00:00Added an answer on June 14, 2026 at 10:26 pm

    Perhaps normalize the string before reading the mapping? Something like this:

    var map = {
      'news/ID/dup' : 'newsDuplicate',
      'news/ID' : 'newsDetail',
      'news/ID/authors' : 'authorsList',
      'news/ID/authors/' : 'authorsList',
      'news/ID/authors/create' : 'authorsCreate',
      'news/ID/authors/:AuthorID' : 'authorDetail',
      'news/ID/authors/:AuthorID/orders' : 'orders',
      'news/ID/authors/:AuthorID/workflow' : 'workflow',
      'news/ID/authors/:AuthorID/tags' : 'tags'
    }
    
    function normalize(str) {
        return str.replace(/news\/\d+/,'news/ID')
    }
    
    var current = map[normalize(url)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application with map and want to zoom to the current location,
I want to read my current location using Map view in my iPhone application.
I want to show current location of user on Google map. Every thing is
I want to make a snapshot of a particular location from the map by
i want to open or focus to my current location in google map in
I want to point to a Google map location using overlay. For this purpose
I want to create an application where users can mark on map location of
In my titanium android application, i want to show a map with certain location
I want to map a location, fill it's adress into an input field and
I want to map a INI file as a python object. So if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.