Get Substring between two other substrings

Searching inside a string for substring. I only know the left and rigth border substrings. Example:
Searching for the substring between "abc" and "ghi". How to do that ?
Who is Participating?
objectsConnect With a Mentor Commented:
String substring = str.substring(str.indexOf(left)+left.length(), str.lastIndexOf(right));
Ajay-SinghConnect With a Mentor Commented:
use contains() function
Gurvinder Pal SinghConnect With a Mentor Commented:
String str = "abcasdasdasdghi";;
int begin = str.indexOf ("abc") + 3;
int end = str.indexOf("ghi");
String requredStr = str.substring(begin, end);
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Kamaraj SubramanianConnect With a Mentor Application Support AnalystCommented:
>>Get Substring between two other substrings

What are you going to do with it when you've go it?
HegemonConnect With a Mentor Commented:
regexps ?
gordon_vt02Connect With a Mentor Commented:
Pattern p = Pattern.compile(".*abc(.*)ghi.*");
String input = "12343234abcsubstringghi1209432890324";
Matcher m = p.matcher(input);
String substring;
if (m.matches()) {
    substring =;
michael_chAuthor Commented:
Thanks a lot, tried your solution objects. Works !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.