yourString.substring(yourString.indexOf("no") + 3 , yourString.length());
Answer from Juned Ahsan on Stack Overflow
Discussions

java - Best method to get substring after a given word in a String? - Stack Overflow
I have a long String, which is a json files contents. Somewhere in this String, it contains the following: "totalWinAmount":100 To find and return this value, I'm currently doing this: int More on stackoverflow.com
🌐 stackoverflow.com
How to grab substring after a specific word in java - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
May 22, 2017
Java - How to extract a substring from start until the end of a particular word in a string? - Stack Overflow
Input string: String sentence = "I am an Administrator of my building"; Desired Output String = "I am an Administrator" Pattern for extracting the substring: Get the substring More on stackoverflow.com
🌐 stackoverflow.com
Java : Getting a substring from a string after certain character - Stack Overflow
I have a string create table temp_username_current_timestamp..... I would like to extract "temp_username_timestamp" from it. Can someone please provide me some help? More on stackoverflow.com
🌐 stackoverflow.com
March 23, 2015
🌐
W3Schools
w3schools.com › java › ref_string_substring.asp
Java String substring() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... The substring() method returns a substring from the string.
🌐
Crunchify
crunchify.com › java j2ee tutorials › in java how to get all text after special character from string?
In Java How to Get all Text After Special Character from String? • Crunchify
November 8, 2021 - package crunchify.com.java.tutorials; /** * @author Crunchify.com * Program: Get everything after Special character like _ or : or * from String in java * */ public class CrunchifyGetStringAfterChar { public static void main(String[] args) { String crunchifyStr = "Hey.. This is Crunchify.com"; String crunchifyStr2 = "HELLO_THIS_IS_CRUNCHIFY_COM"; String crunchifyStr3 = "This is simple substring example *"; // substring(): Returns a string that is a substring of this string.
🌐
Learn IT University
learn-it-university.com › home › extracting substring after specific word in a string
Extracting Substring After Specific Word in a String - Learn IT University
July 9, 2024 - This can be achieved by using the substring method in combination with the indexOf method to find the position of the word and then extract the substring starting from that position.
🌐
Baeldung
baeldung.com › home › java › java string › get substring from string in java
Get Substring from String in Java | Baeldung
July 21, 2024 - For more details on the Java regular expressions check out this tutorial. We can use the split method from the String class to extract a substring. Say we want to extract the first sentence from the example String.
🌐
Hackr
hackr.io › home › articles › programming
Java Substring Extraction [with Code Examples]
January 30, 2025 - When it comes to Java, we have access to a range of string methods that are part of the String class. This tutorial provides various code examples and walkthroughs for the built-in Java substring method .substring() to extract a Java Substring.
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-string-substring-method-example
Java String substring() Method with examples
Note: The method is called like this: substring(start + 1, end), here start index is +1 because, we want to get the substring after the delimiter position, however the end index is not +1 because end index is not inclusive in substring method. public class JavaExample{ public static void ...
🌐
iO Flood
ioflood.com › blog › java-substring
Java Substring: Extraction and Manipulation Guide
February 20, 2024 - For example, extracting dynamic substrings within loops or conditional statements, which can be quite useful in real-world programming tasks. Consider the following example where we use a loop to extract and print each word from a sentence: String sentence = 'Java is fun'; int i = 0; while(i < sentence.length()) { int spaceIndex = sentence.indexOf(' ', i); if(spaceIndex == -1) { spaceIndex = sentence.length(); } String word = sentence.substring(i, spaceIndex); System.out.println(word); i = spaceIndex + 1; } // Output: // 'Java' // 'is' // 'fun'
🌐
Javatpoint
javatpoint.com › java-string-substring
Java String substring()
Java String substring() method with method signature and examples of concat, compare, touppercase, tolowercase, trim, length, equals, split, string substring in java etc.
🌐
CodingTechRoom
codingtechroom.com › question › extract-substring-after-word
How to Extract a Substring from a String After a Specific Word in Programming? - CodingTechRoom
Extracting a substring from a string after a specific word is a common task in programming. This can be achieved using various string manipulation techniques depending on the programming language used. Below, we will cover how to do this in multiple languages, including Python, JavaScript, and Java.
Top answer
1 of 2
1

Assuming you are trying to find parent location of specified file simplest way would be using File class or Path instead of String methods. Your code will be more readable and probably safer.

Using java.io.File:

String location = "/abc/def/ghfj.doc";

File f = new File(location);
String parentName = f.getParentFile().getName();

System.out.println(parentName);

Using java.nio.file.Path:

String location = "/abc/def/ghfj.doc";

Path p = Paths.get(location);
String parent = p.getParent().getFileName().toString();

System.out.println(parent);

Output in both cases: def


In case of selecting def in /abc/def/ghfj/ijk/lmn.doc you could use Path#getName(N) where N is zero-based index of elements from farthermost ancestor to selected file like abc is 0, def is 1,...

So your code can look like:

String location = "/abc/def/ghfj/ijk/lmn.doc";

Path p = Paths.get(location);
String parent = p.getName(1).getFileName().toString();

System.out.println(parent);// Output: def
2 of 2
0

Quick and dirty solution using a regular expression and groups:

public class AClass {

    private static final String TEXT = "/abc/def/ghfj/ijk/lmn.doc";
    private static final String REGULAR_EXPRESSION = "(/[^/]*){2}/([^/]*)/.*";

    public static void main(final String[] args) {
        final Pattern pattern = Pattern.compile(REGULAR_EXPRESSION);
        final Matcher matcher = pattern.matcher(TEXT);
        if (matcher.matches()) {
            // the following variable holds "ghfj"
            String value = matcher.group(2);
            System.out.println(value);
        }
    }
}

Now you need to be more precise in order to allow us to fine tune the regular expression to your concrete needs.

Edit: I edited the solution according to your own edit. The regular expression has to be understood as follows:

  • (/[^/]*){2} : two times the character / followed by any character except /
  • / : an additional /character
  • ([^/]*) : a group of characters not containing /
  • /.* : a / character followed by any other character

Then matcher.group(2) returns the String held by the group represented by the ([^/]*) part of the above regular expression.

🌐
Coderanch
coderanch.com › t › 386253 › java › finding-character-specific-word-String
finding the character after a specific word in a String (Java in General forum at Coderanch)
I have a string "3.100.2.100" and I have to read the immediate value of the character which is after the 3rd DOT(.) character.
🌐
Intellipaat
intellipaat.com › home › blog › substring in java: examples, methods and applications
What is Substring in Java: Examples and Methods to Extract a Substring
August 5, 2025 - The substring (int begIndex, int endIndex) method in Java takes two parameters, begIndex and endIndex, indicating the starting and ending indices of the substring, respectively. The substring extracted lies between the character at begIndex and the character at the endIndex – 1. The syntax for extracting a substring using this particular method is: public String substring(int begIndex, int endIndex)...