Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract the string between two "/" characters

Tags:

java

So I'm trying to extract the strings between the / delimiters of the url. This has proven to be a bit hard for me as Java does not accept "/" as a char.

String temp = "svn+ssh://xxxxxx.net/var/lib/webprojects/xxx/xxx/WebContent/images/Calendar_icon.png";

How could I get, from this String : images , WebContent , etc... ?

like image 863
Jordi Avatar asked Jun 11 '15 12:06

Jordi


People also ask

How do I extract a string between two characters in Python?

Using index() + loop to extract string between two substrings. In this, we get the indices of both the substrings using index(), then a loop is used to iterate within the index to find the required string between them.

How do I extract text between characters in Excel?

Extracting text between characters in Excel 365 In Excel 365, you can get text between characters more easily by using the TEXTBEFORE and TEXTAFTER functions together. This formula also works nicely for extracting text between two occurrences of the same character.

How do I extract text from two characters in a sheet?

To extract the text between any characters, use a formula with the MID and FIND functions. The FIND Function locates the parenthesis and the MID Function returns the characters in between them.


3 Answers

How about splitting the string by / -

String[] parts = temp.split("/");

and accessing the relevant parts by their index positions.

like image 153
MD Sayem Ahmed Avatar answered Nov 15 '22 01:11

MD Sayem Ahmed


First, use a regex to remove what you don't want:

String temp = temp.replaceAll("^.*//xxxxxx.net","");

Then split it:

String[] parts = temp.split("/");
like image 33
Dakkaron Avatar answered Nov 14 '22 23:11

Dakkaron


You should use split function. With this, you will have your String divide in an array of Strings by the positions of where "/" it's placed. So, for example, if you want to access to the url, in your case will be:

String split[] = temp.split("/"); //Here you have your String divide.

So, to access to the url (look that it is on the second position of the array (because in the first position it's svn+ssh:) you will have to do:

split[1];

I expect it will be helpful for you!

like image 35
Francisco Romero Avatar answered Nov 14 '22 23:11

Francisco Romero