用于URL捕获的JavaScript中的正则表达式 [英] Regular Expressions in JavaScript for URL Capture
本文介绍了用于URL捕获的JavaScript中的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对Javascript中的正则表达式不太好。有没有人知道捕获URL的最后部分的有效方法???
I am not too good with Regular Expressions in Javascript. Does anyone know an efficient way to capture the last portion of a URL???
我有以下网址:
http://localhost:3000/developers/568d3c3c82eea6e6fb47c236
<我需要做的就是捕获开发者ID(即568d3c3c82eea6e6fb47c236)。这条路线总是一样的(只有ID的变化)。
And all I need to do is capture the developer ID (which is 568d3c3c82eea6e6fb47c236). This route will always be the same (with just the ID's changing).
任何帮助都会非常感激
推荐答案
您可以通过 /
使用拆分
并获取srray的最后一个元素:
You can use split
by /
and get the last element of srray:
var last = 'http://localhost:3000/developers/568d3c3c82eea6e6fb47c236'.split('/').pop();
//=> 568d3c3c82eea6e6fb47c236
这篇关于用于URL捕获的JavaScript中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文