Assuming you want the part between single quotes, use this regular expression with a Matcher:

"'(.*?)'"

Example:

String mydata = "some string with 'the data i want' inside";
Pattern pattern = Pattern.compile("'(.*?)'");
Matcher matcher = pattern.matcher(mydata);
if (matcher.find())
{
    System.out.println(matcher.group(1));
}

Result:

the data i want
Answer from Mark Byers on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_regex.asp
Java Regular Expressions
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Pattern pattern = Pattern.compile("w3schools", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher("Visit W3Schools!"); boolean matchFound = matcher.find(); if(matchFound) { System.out.println("Match found"); } else { System.out.println("Match not found"); } } } // Outputs Match found
Discussions

Regex to find the Substring in a String and also it's preceding number
Hello, I have an issue with the Regex to find the exact string from the given Input txt and also it’s number. Note: I need these values in two different variables(one to find GROOT in the given string and the other one if for the number corresponding to it if found). More on forum.uipath.com
🌐 forum.uipath.com
9
1
July 1, 2020
regex - Using Java to find substring of a bigger string using Regular Expression - Stack Overflow
If I have a string like this: FOO[BAR] I need a generic way to get the "BAR" string out of the string so that no matter what string is between the square brackets it would be able to get the strin... More on stackoverflow.com
🌐 stackoverflow.com
string - Extracting a substring of a known pattern in java - Stack Overflow
The substring is always of the form "USX", where US is the string "US", and X is an integer of arbitrary length. ... For the following strings, I would want to extract the text in bold. ... I have searched around for a way of doing this, but was unsuccessful. Any ideas on how I might be able to solve this? ... You can achieve it using regex... More on stackoverflow.com
🌐 stackoverflow.com
mommyHalpImScaredOfRegex
The annoying part is that across languages everything works slightly different. When do you need to escape stuff? When you replace what is the placeholder? How do you do multiline regex etc… More on reddit.com
🌐 r/ProgrammerHumor
586
11307
March 14, 2026
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › regex › Pattern.html
Pattern (Java Platform SE 8 )
April 21, 2026 - Pattern.matches(regex, input); behaves in exactly the same way as the expression ... If a pattern is to be used multiple times, compiling it once and reusing it will be more efficient than invoking this method each time. ... Splits the given input sequence around matches of this pattern.
🌐
Baeldung
baeldung.com › home › java › java string › get substring from string in java
Get Substring from String in Java | Baeldung
July 21, 2024 - As there are multiple “<% … %>” pairs, we would like to obtain a List as the result: List<String> expected = List.of("One", "Two", "Three"); We can employ the regex’s Pattern and Matcher to do the job.
🌐
Medium
medium.com › stackera › java-regex-part-4-replacing-and-extracting-text-6eecdbf7f5e8
Java RegEx: Part 4— Replacing and Extracting Text | by Sera Ng. | Tech Training Space | Medium
October 18, 2020 - The java.lang.String class in Java supports 2 methods for these purposes: replace() and replaceAll() ... In the string, there are some upper case I letters and I want to replace them with a lower case i letter.
🌐
GeeksforGeeks
geeksforgeeks.org › java › regular-expressions-in-java
Regular Expressions in Java - GeeksforGeeks
May 22, 2026 - Regex can split text, validate input, and extract data efficiently in Java.
🌐
Coderanch
coderanch.com › t › 590292 › java › Regex-extract-substring
Regex to extract a substring (Java in General forum at Coderanch)
Chandra shekar M wrote:So i want to define a regex in such a way that i should be able to extract everything after http:// and out put should be [email protected] and 8080. How can i do this? Just remove the brackets from the first expression. However, I wonder why you think you need to do this.
Find elsewhere
🌐
Vogella
vogella.com › tutorials › JavaRegularExpressions › article.html
Regular expressions in Java - Tutorial
May 31, 2026 - This tutorial describes the usage of regular expressions in Java with modern examples and best practices. It covers basic regex syntax, Java’s Pattern and Matcher classes, practical examples for common use cases, and important security considerations.
🌐
JRebel
jrebel.com › blog › java-regular-expressions-cheat-sheet
Java Regular Expressions (Regex) Cheat Sheet | JRebel
A Java Regex processor translates a regular expression into an internal representation which can be executed and matched against the text being searched. It will tell you whether a string is in the set of strings defined by a pattern or find ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
April 21, 2026 - An invocation of this method of ... string contains the specified sequence of char values. ... Replaces the first substring of this string that matches the given regular expression with the given replacement....
🌐
UiPath Community
forum.uipath.com › help › studio
Regex to find the Substring in a String and also it's preceding number - Studio - UiPath Community Forum
July 1, 2020 - Hello, I have an issue with the Regex to find the exact string from the given Input txt and also it’s number. Note: I need these values in two different variables(one to find GROOT in the given string and the other one…
🌐
GeeksforGeeks
geeksforgeeks.org › java › extracting-word-string-java
Extracting each word from a String using Regex in Java - GeeksforGeeks
July 23, 2025 - // Java program to demonstrate extracting words // from string using Regex import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { String s1 = "Geeks for Geeks"; String s2 = "A Computer Science Portal for Geeks"; Pattern p = Pattern.compile("[a-zA-Z]+"); Matcher m1 = p.matcher(s1); Matcher m2 = p.matcher(s2); System.out.println("Words from string \"" + s1 + "\" : "); while (m1.find()) { System.out.println(m1.group()); } System.out.println("Words from string \"" + s2 + "\" : "); while (m2.find()) { System.out.println(m2.group()); } } } Output:
🌐
Regex101
regex101.com
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
🌐
RegExr
regexr.com
RegExr: Learn, Build, & Test RegEx
RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).
🌐
LeetCode
leetcode.com › problems › regular-expression-matching
Regular Expression Matching - LeetCode
Can you solve this real interview question? Regular Expression Matching - Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where: * '.' Matches any single character. * '*' Matches zero or more of the preceding element.
🌐
Reddit
reddit.com › r/programmerhumor › mommyhalpimscaredofregex
r/ProgrammerHumor on Reddit: mommyHalpImScaredOfRegex
March 14, 2026 - Claude has gotten so good on newer models for Java, JS, and Python that IMO you're limiting yourself if you're already a competent engineer and dont use it. ... I will ask it to write a regex to find x thing in y language then use regex101.com to fix it (I only code hobby projects).
🌐
Medium
medium.com › @kaustubh.saha › regular-expressions-in-java-b806152aaa93
Regular Expressions in Java. A regular expression is essentially a… | by Kaustubh Saha | Medium
November 29, 2025 - In Java, capturing groups are defined by enclosing a part of your regex pattern in parentheses ( ). Extraction (The most common use): When a regex engine finds a match for a pattern inside parentheses, it “captures” that specific substring ...