Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
EvoticTalend
Contributor
Contributor

How to extract a substring from a "/" to "." ?

Hello everyone, I've had a difficult day searching how to extract a string from a "/" to a ".".

Example: https://ilursei.com/photos/1943/161317/077666rtryfggghvbvnfggfh46546rtrtrg4_123.jpg

I want to extract only the large series of numbers "

077666rtryfggghvbvnfggfh46546rtrtrg4_123" to before ".jpg"

I tried tExtractRegexFields, some StringHandlings functions like CHANGE or eExtract but none result.

Labels (3)
1 Solution

Accepted Solutions
Prakhar1
Creator III
Creator III

Hi I guess you are reading from excel.

So for example the column name in excel is "data"

your flow will be like

 

tFileInputExcel --> tFlowtoIterate -> tJavaFlex

 

Now you have to write your code in the main part of tJavaflex and it will look like

 

Start Code

int first,second;

String text;

 

Main Code :

first = (row1.data).lastIndexOf("/");

second = (row1.data).lastIndexOf(".");

 

text = (row1.data).substring(first+1, second);

System.out.println(text);

 

Row1 is the name of outgoing link of tFileInput Excel

View solution in original post

12 Replies
Prakhar1
Creator III
Creator III

try this below code in tJavaFlex or tJava

 

String foo = "https://ilursei.com/photos/1943/161317/077666rtryfggghvbvnfggfh46546rtrtrg4_123.jpg";

 

int first = foo.lastIndexOf("/");

int second = foo.lastIndexOf(".");

 

String text = foo.substring(first+1, second);

 

System.out.println(text);

gjeremy1617088143

Hi you can try this regex : (?<=/\\d{1,10}/\\d{1,10}/)(.{1,100})(?=(\\..{3,4}$))

Send me Love and Kudos

EvoticTalend
Contributor
Contributor
Author

Thank you for the response Prakhar.

 

There is a little problem, I can't enter manually the link because I have a column with this links, so instead of the link "https://ilursei.com..." how can i put the name of a column from an Excel file?

 

Thanks.

EvoticTalend
Contributor
Contributor
Author

Thank you for the response gjeremy

 

Seems not working, I put the Excel file (the origin of the column with this links), the tExtractRegexField component with your code and a tLogRow, .

gjeremy1617088143

have you put the regex in the field with doble quote like this "(?<=/\\d{1,10}/\\d{1,10}/)(.{1,100})(?=(\\..{3,4}$))" ?

cause i try it with a tfileinputregex with your text and it's working

Prakhar1
Creator III
Creator III

Hi I guess you are reading from excel.

So for example the column name in excel is "data"

your flow will be like

 

tFileInputExcel --> tFlowtoIterate -> tJavaFlex

 

Now you have to write your code in the main part of tJavaflex and it will look like

 

Start Code

int first,second;

String text;

 

Main Code :

first = (row1.data).lastIndexOf("/");

second = (row1.data).lastIndexOf(".");

 

text = (row1.data).substring(first+1, second);

System.out.println(text);

 

Row1 is the name of outgoing link of tFileInput Excel

gjeremy1617088143

the Prakhar solution seem much simpler i think you will go as he say with the last index of / and .

you could use it directly on a tmap output :

 

(row1.data).substring((row1.data).lastIndexOf("/") + 1, (row1.data).lastIndexOf("."))

EvoticTalend
Contributor
Contributor
Author

Thank you for the response, gjeremy. Yes, I have to use this column in a tmap but I have another problem that is I have to have this substring prepared in a tmap to match with a column in other Excel file (foreign key) and then send data to a Database.

 

The flow would be:

-InputExcel1 (with the column I want to do the substring()) and -InputExcel2 (Another columns)

 

-tMap to match the column with substring() prepared to other column in the InputExcel2

 

-tDBOutput

 

 

 

How can I do the substring before the tMap to match correctly this column with substring to other column in the other Excel file? I think I can't do the substring function in the tMap before I can match these two columns.

 

Thank You.

Prakhar1
Creator III
Creator III

-InputExcel1 --> tJavaFlex --> tMap-->tDbOutput

use the code in tJavaFlex which I told you