How can REGEX be used to extract the ID at the end of a URL excluding the forward slash

Struggling with a GreaseMonkey script and need help with a REGEX to extract the ID from a URL of an article.

Here is an example URL:

I want to extract the ID at the end after the comma: 272317

I tried using this REGEX: (,([\d]+)) to only capture digits after the comma, which gave me ,272317 but I don't want the comma at the beginning.

Any suggestions on how to improve my REGEX?

Thank you in advance :)

Answer №1

To successfully extract the digits, it is advisable to eliminate the outer paranthesis as they are not required for capturing the target numbers.

,(\d+)$

Answer №2

A creative solution that avoids using regex:

const link = 'https://www.example.com/cat-video-fun-times-123,987654';
link.slice(link.lastIndexOf(',') + 1);

To find the digits at the end of the link, you could use the regular expression (\d+)$, but it wouldn't account for the comma.

Answer №3

Give this a shot: (?!,)([0-9]+){5}. This regex pattern should work well if the numerical ID is greater than 5.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting a Recursive Menu Problem in Vue.js

I've been attempting to create a recursive menu in Vue.js, but I keep encountering an error and I'm struggling to identify the issue. Here is my current structure: MenuList.vue <template> <ul class="menu"> <MenuLink v ...

Encountered a 'SyntaxError: await is only valid in async function' error while trying to utilize the top-level await feature in Node v14.14.0

I'm excited to use the new top-level await feature that was introduced in Node version 14.8. For more information, you can check out this link and here. I did a thorough search but couldn't find any questions related to issues with the new featur ...

How can you use the :not selector in CSS to target specific elements within a group?

Consider the following set of inputs: <div id="group"> <input id="uno" class="red"></input><br/> <input id="dos" class="red"></input><br/> <input id="tres" class="blue"></input><br/ ...

Node.js (npm) is still unable to locate python despite setting %PYTHON% beforehand

Trying to get Node.js to work is proving to be more challenging than expected! Despite having two versions of Python on my computer, it seems that Node.js only works with the older version, 2.7. When I encountered an error, it prompted me to set the path ...

Tips for aligning a div to the top of a different div

Located within the content div is the first div known as the '#icon-selection-menu' bar. Its default position is set to absolute with top:0px and left:0px, causing it to appear in the top left corner of the content div. Further down within the c ...

Mapping Data Dynamically Between Parent and Child Components with Vue.js

It seems like I am headed towards a path of inefficiency when it comes to keeping data properly synced between Parent and Child components. For instance, if I have a basic Child Vue element like the one below: common/InputText.vue <template> &l ...

Passing component properties using spaces in VueJS is a simple and effective

I am encountering an issue where I want to pass component props from my view, but I am facing a challenge due to the presence of a space in the value. This causes Vue to return the following error: vendor.js:695 [Vue warn]: Error compiling template: - inva ...

Using the ng-repeat directive along with the string replace expression allows for dynamically

Struggling to find a way to remove a substring within an angular expression while using the ng-repeat directive. The controller resides in an external JavaScript file, and here is the corresponding HTML code snippet. function myController($scope, $http ...

Passing a single item from a list as a prop in Vue.js

Imagine having the following set of information in data: data: { todos: [ { id: 1, title: "Learn Python" }, { id: 2, title: "Learn JS" }, { id: 3, title: "Create WebApp" } ] } Now, I aim to send only the item with an id of 2 t ...

Rotate object within HTML table

I have a simple data structure as shown below: [ { "ClientId": 512, "ProductId": 7779, "Date": "2019-01-01", "Quantity": 20.5, "Value": 10.5 }, { "ClientId": 512, "ProductId": ...

Dreamweaver and jQuery collaboration for displaying PDFs in a container

I am currently utilizing the jQuery accordion functionality within the latest version of Dreamweaver. My goal is to link a specific PDF with each account so that when an account is selected, the corresponding PDF will open in the designated "content goes h ...

The behavior of ReactJS's componentDidMount seems to conflict with Bootstrap's expected functionality

I am trying to apply $(dom).popover() on a rendered DOM. Here is my current code: module.exports = React.createClass({ componentDidMount: function() { $(this.getDOMNode()).popover(); }, render: function() { return ( // My DOM ) ...

Prevent duplication in HTTP POST requests using Express and Node.js

How can I prevent a duplicate object from being created during a post request if the object already exists? I have included my code and JSON object below. I attempted to use next(), but it did not work as expected, resulting in a new object with a differen ...

Difficulty encountered in assigning a value to a variable when utilizing an async function in Node.js

While attempting to retrieve the jwtauthtoken from the user and passing it to a function called getUserId() in the imported JavaScript file, I encountered an issue where the returned value was undefined instead of the decoded ID. The getUserId() function ...

Getting the URL path within getStaticPaths in Next.js

Is there a way to retrieve the last number from the current URL pathnames in getStaticPaths? http://localhost:3000/category/food/2 -> 2, http://localhost:3000/category/food/3 -> 3, ... I have attempted: export const getStaticPaths: GetStaticPaths = ...

Swap two frames effortlessly with just a single click!

Is there a way to effortlessly change the contents of two frames with just one click? With a single click, I'd like to modify both "framename" and "framename2" by setting their href attribute to 'qwerty' and 'qwerty2' respectively ...

How to retrieve headers using Express.js middleware

My middleware creates authentication API keys that are then added to the header. const loger = require("easy-loger"); require('dotenv').config(); function authMiddleware(req, res, next){ const appApiKey = process.env.API_KEY; l ...

How come the data I send gets converted to Undefined when working with Tabulator?

I am currently facing an issue with integrating JSON data as search results into my Tabulator. The goal is to display these search results in their respective columns within the Tabulator. Here is the code snippet I have implemented: <body> <div ...

Limit the input to a maximum number of characters

I am in need of input boxes that only accept hexadecimal characters and I also want to set a maximum length for the input. Although I have successfully implemented accepting hex characters only, I am facing an issue when pasting a string - the invalid cha ...

React state change is causing a functional component to not re-render

When attempting to map out a nested array from the data retrieved by an http request in a functional component, you may encounter a frustrating error: "TypeError: Cannot read property 'map' of undefined". Even though the state is updated correctl ...