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

  • SEARCH
  • Home
  • 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 8036109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:30:46+00:00 2026-06-05T02:30:46+00:00

Give the following string: http://foobar.com/trusted/123/views/AnalyticsInc ..where 123 will be a number anywhere between 0

  • 0

Give the following string:

http://foobar.com/trusted/123/views/AnalyticsInc

..where 123 will be a number anywhere between 0 and 9999999, I need to be able to dynamically replace said value with a different value

I assume the best way to approach this is to do a string.replace with some sort of regex pattern, since we can count on the fact that “/trusted/” and “/views/” will always surround the value that needs to be swapped out.

var foo='http://foobar.com/trusted/123/views/AnalyticsInc';
var newvalue=654321;
magic(); //magic happens here
console.log(foo); //returns http://foobar.com/trusted/654321/views/...etc

But my regex kung-fu is so weak I cannot defeat a kitten. Can someone give me a hand? Or if there’s a better approach, I’d love to learn it. Thanks!

  • 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-05T02:30:47+00:00Added an answer on June 5, 2026 at 2:30 am

    It will replace the first occurrence of number from 0 to 9999999 in foo string:

    foo = foo.replace(/\d{1,7}/, newvalue);
    

    DEMO: http://jsfiddle.net/D4teZ/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service that give me a date time string in the following
I need a regex that will give me the following results from each example
Its my understanding that the questions in StackOverflow has the following format http://stackoverflow.com/questions/{question-id}/{slug-made-from-question-title} So
Why do the following URLs give me the IIS errors below: A) http://192.168.1.96/cms/View.aspx/Show/Small+test '
I'm sitting at a PowerShell command prompt and following http://technet.microsoft.com/en-us/library/dd347632.aspx PS C:\> [System.Math]::Sqrt (9)
While Compiling the WPF Application for many times in a day it give following
Give the following XML I'm trying to update the UpgradeImage and TargetImage SourceFile attributes
Why does the following give no compilation error?: // T.h template<class T> class X
Why does the following code give me an error (g++ 4.1.2)? template<class A> class
Why does the following code give me a segmentation fault? #define MAXROWS 10 #define

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.