1

I'm doing some string manipulation and I'm very bad at regular expression. I have some string like:

/sonata-economy-analog-watch-men/p/itmda5wagvmtttwr

I want to replace everything before the last forward slash by a blank and get only "itmda5wagvmtttwr". Does anyone know how to do this with regular expressions?

Updated - Actually I'm doing this in xml.

        let $url :=data($item//a[@class="fk-anchor-link"]/@href)
        let $temp :=fn:substring-before($url, "?")
    let $temp2 :=fn:replace()

In url I will get string as

/titan-htse-analog-watch-men/p/itmd9gjfprgdt8d8?pid=WATD9H76AMCWDYT5&ref=28b766fc-2692-4ba3-a4cb-ea8a060cc9ec

And using fn:substring-before($url, "?") I have taken everything before ? and in temp I'm getting,

/titan-htse-analog-watch-men/p/itmd9gjfprgdt8d8

Now I want to replace everything before last "/" and get only "itmd9gjfprgdt8d8" in temp2

4

2 回答 2

1

你可以搜索

[^/]*$

它为您提供了与字符串末尾相邻的所有非斜杠字符。

于 2013-01-15T07:43:55.110 回答
0

您可以使用- 等效项:http-after : //www.xqueryfunctions.com/xq/functx_substring-after-last.htmlfn_substring-before

let $temp :=fn:substring-after-last(fn:substring-before($url, "?"), "/")

不需要正则表达式:)

于 2013-01-15T08:18:35.843 回答