TransWikia.com

Last part of a url (after the "/")

Mathematica Asked by Aryan on January 21, 2021

I want the last number after the "/". How can I do that?

"http://arxiv.org/abs/math/0208009v1"

I just want 0208009v1

I want to import multiple links from the following:

{{"http://arxiv.org/abs/math/0208009v1"}, 
{"http://arxiv.org/abs/0905.0227v1"}, 
{"http://arxiv.org/abs/0907.5143v2"}, 
{"http://arxiv.org/abs/math/0509348v1"}, 
{"http://arxiv.org/abs/math/0608711v2"}, 
{"http://arxiv.org/abs/math-ph/0002018v2"}}

I just want the last number in the following links. How would that work?

2 Answers

list = {{"http://arxiv.org/abs/math/0208009v1"}, 
 {"http://arxiv.org/abs/0905.0227v1"}, 
 {"http://arxiv.org/abs/0907.5143v2"},
 {"http://arxiv.org/abs/math/0509348v1"}, 
 {"http://arxiv.org/abs/math/0608711v2"}, 
 {"http://arxiv.org/abs/math-ph/0002018v2"}};

In addition to StringSplit suggested by J.M. in comments,

StringSplit[Flatten@list, "/"][[All, -1]]

you can also use

StringTrim

StringTrim[Flatten[list], StartOfString ~~ ___ ~~ "/"]

StringReplace

StringReplace[Flatten[list], StartOfString ~~ ___ ~~ "/" -> ""]

StringCases

Flatten @ StringCases[Flatten@list, "/" ~~ a : Except["/"] .. ~~ EndOfString :> a]

StringDrop + StringPosition:

MapThread[StringDrop, {Flatten@list, Max /@ StringPosition[Flatten@list, "/"]}]

FileNameSplit

Last /@ FileNameSplit /@ Flatten[list]

to get

{"0208009v1", "0905.0227v1", "0907.5143v2", "0509348v1", "0608711v2",    "0002018v2"}

Answered by kglr on January 21, 2021

In addition, using a modification of this regex:

(StringCases[#, RegularExpression["[^/]+$"]]&/@list)//Flatten

{0208009v1, 0905.0227v1, 0907.5143v2, 0509348v1, 0608711v2, 0002018v2}

where

list = {{"http://arxiv.org/abs/math/0208009v1"}, 
{"http://arxiv.org/abs/0905.0227v1"}, 
{"http://arxiv.org/abs/0907.5143v2"},
{"http://arxiv.org/abs/math/0509348v1"}, 
{"http://arxiv.org/abs/math/0608711v2"}, 
{"http://arxiv.org/abs/math-ph/0002018v2"}};

Answered by user1066 on January 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP