Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract substring after a certain pattern

Tags:

java

string

split

I have the following string:

http://xxx/Content/SiteFiles/30/32531a5d-b0b1-4a8b-9029-b48f0eb40a34/05%20%20LEISURE.mp3?&mydownloads=true

How can I extract the part after 30/? In this case, it's 32531a5d-b0b1-4a8b-9029-b48f0eb40a34.I have another strings having same part upto 30/ and after that every string having different id upto next / which I want.

like image 624
user1196969 Avatar asked Jun 06 '12 04:06

user1196969


People also ask

How do I get a substring after a specific character?

To get the substring after a specific character, call the substring() method, passing it the index after the character's index as a parameter. The substring method will return the part of the string after the specified character.

How do you extract a certain part of a string?

The substr() method extracts a part of a string. The substr() method begins at a specified position, and returns a specified number of characters. The substr() method does not change the original string. To extract characters from the end of the string, use a negative start position.

How do I extract a specific pattern from a string in python?

Use re.search() to extract a substring matching a regular expression pattern. Specify the regular expression pattern as the first parameter and the target string as the second parameter. \d matches a digit character, and + matches one or more repetitions of the preceding pattern.


1 Answers

You can do like this:

String s = "http://xxx/Content/SiteFiles/30/32531a5d-b0b1-4a8b-9029-b48f0eb40a34/05%20%20LEISURE.mp3?&mydownloads=true";
        System.out.println(s.substring(s.indexOf("30/")+3, s.length()));
like image 89
UVM Avatar answered Oct 05 '22 20:10

UVM