链接的正则表达式 [英] regular expression for link

查看:194
本文介绍了链接的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修剪这个字符串 - > http:// hokuspokus / ixdebude / ix 我完全需要这个字符串的一部分 / ixdebude / ix

i need to trim this string -> http://hokuspokus/ixdebude/ix and i exactly Need this part of the string /ixdebude/ix

我有2个表达式来解决我的问题。

I have 2 expressions to solve my Problem.

我的第一个正则表达式 - >

My first regex ->

/(。*)\ /(。*)(\ /)(。* )\ / * / g 返回数组[5]组。

我的第二个正则表达式 - >

my second regex ->

/(\ /\....)$(.*?)$/ g 返回 / ixdebude / ix

有人可以给我另一个正则表达式,没有千点的更好吗?

Can someone of you give me another regex, a better without thousand dots ?

推荐答案

你可以使用这样的正则表达式:

You could use a regex like this:

//.*?(/.*)

工作演示

Working demo

对于javascript,您可以使用:

For javascript, you could use:

var re = /\/\/.*?(\/.*)/; 
var str = 'http://hokuspokus/ixdebude/ix';
var m;

if ((m = re.exec(str)) !== null) {
    if (m.index === re.lastIndex) {
        re.lastIndex++;
    }
    // View your result using the m-variable.
    // eg m[0] etc.
}

这篇关于链接的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆