Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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
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);
Hi you can try this regex : (?<=/\\d{1,10}/\\d{1,10}/)(.{1,100})(?=(\\..{3,4}$))
Send me Love and Kudos
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.
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, .
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
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
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("."))
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.
-InputExcel1 --> tJavaFlex --> tMap-->tDbOutput
use the code in tJavaFlex which I told you