(answer changed after OP added more details)

Your string

String inputText = "\1f\1e\1d\02002868BF03030000000000000000S023\1f\1e\1d\03\0d";

Doesn't actually contains any \ literals because according to Java Language Specification in section 3.10.6. Escape Sequences for Character and String Literals \xxx will be interpreted as character indexed in Unicode Table with octal (base/radix 8) value represented by xxx part.

Example \123 = 1*82 + 2*81 + 3*80 = 1*64 + 2*8 + 3*1 = 64+16+3 = 83 which represents character S

If string you presented in your question is written exactly the same in your text file then you should write it as

String inputText = "\\1f\\1e\\1d\\02002868BF03030000000000000000S023\\1f\\1e\\1d\\03\\0d";

(with escaped \ which now will represent literal).


(older version of my answer)

It is hard to tell what exactly you did wrong without seeing your code. You should be able to find at least \1, \1, \1, \0 since your regex can match one \ and one hexadecimal character placed after it.

Anyway this is how you can find results you mentioned in question:

String text = "\\1f\\1e\\1d\\020028";
Pattern p = Pattern.compile("\\\\[a-fA-F0-9]{2}");
//                                          ^^^--we want to find two hexadecimal 
//                                               characters after \
Matcher m = p.matcher(text);
while (m.find())
    System.out.println(m.group());

Output:

\1f
\1e
\1d
\02
Answer from Pshemo on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › regex › Pattern.html
Pattern (Java Platform SE 8 )
July 21, 2026 - This method compiles an expression and matches an input sequence against it in a single invocation. The statement · boolean b = Pattern.matches("a*b", "aaaaab"); is equivalent to the three statements above, though for repeated matches it is less efficient since it does not allow the compiled ...
🌐
Dev.java
dev.java › learn › pattern-matching
Using Pattern Matching - Dev.java
December 21, 2022 - In our example, the variable o is the element you need to match; it is your matched target. The pattern is the String s declaration. The result of the matching is the variable s declared along with the type String.
Top answer
1 of 4
2

(answer changed after OP added more details)

Your string

String inputText = "\1f\1e\1d\02002868BF03030000000000000000S023\1f\1e\1d\03\0d";

Doesn't actually contains any \ literals because according to Java Language Specification in section 3.10.6. Escape Sequences for Character and String Literals \xxx will be interpreted as character indexed in Unicode Table with octal (base/radix 8) value represented by xxx part.

Example \123 = 1*82 + 2*81 + 3*80 = 1*64 + 2*8 + 3*1 = 64+16+3 = 83 which represents character S

If string you presented in your question is written exactly the same in your text file then you should write it as

String inputText = "\\1f\\1e\\1d\\02002868BF03030000000000000000S023\\1f\\1e\\1d\\03\\0d";

(with escaped \ which now will represent literal).


(older version of my answer)

It is hard to tell what exactly you did wrong without seeing your code. You should be able to find at least \1, \1, \1, \0 since your regex can match one \ and one hexadecimal character placed after it.

Anyway this is how you can find results you mentioned in question:

String text = "\\1f\\1e\\1d\\020028";
Pattern p = Pattern.compile("\\\\[a-fA-F0-9]{2}");
//                                          ^^^--we want to find two hexadecimal 
//                                               characters after \
Matcher m = p.matcher(text);
while (m.find())
    System.out.println(m.group());

Output:

\1f
\1e
\1d
\02
2 of 4
1

You need to read the file properly and replace '\' characters with '\\'. Assume that there is file called test_file in your project with this content:

\1f\1e\1d\02002868BF03030000000000000000S023\1f\1e\1d\03\0d

Here is the code to read the file and extract values:

public static void main(String[] args) throws IOException, URISyntaxException {        
    Test t = new Test();
    t.test();
}

public void test() throws IOException {        
    BufferedReader br =
        new BufferedReader(
            new InputStreamReader(
                getClass().getResourceAsStream("/test_file.txt"), "UTF-8"));
    String inputText;

    while ((inputText = br.readLine()) != null) {
        inputText = inputText.replace("\\", "\\\\");

        Pattern pattern = Pattern.compile("\\\\[a-fA-F0-9]{2}");
        Matcher match = pattern.matcher(inputText);

        while (match.find()) {
            System.out.println(match.group());
        }
    }
}
🌐
W3Schools
w3schools.com › java › java_regex.asp
Java Regular Expressions
The matcher() method is used to search for the pattern in a string. It returns a Matcher object which contains information about the search that was performed. The find() method returns true if the pattern was found in the string and false if ...
🌐
Jenkov
jenkov.com › tutorials › java-regex › matcher.html
Java Regex - Matcher
November 6, 2017 - Here is a Java Matcher find(), start() and end() example: import java.util.regex.Pattern; import java.util.regex.Matcher; public class MatcherFindStartEndExample { public static void main(String[] args) { String text = "This is the text which is to be searched " + "for occurrences of the word 'is'."; String patternString = "is"; Pattern pattern = Pattern.compile(patternString); Matcher matcher = pattern.matcher(text); int count = 0; while(matcher.find()) { count++; System.out.println("found: " + count + " : " + matcher.start() + " - " + matcher.end()); } } }
🌐
Baeldung
baeldung.com › home › java › core java › a guide to java regular expressions api
A Guide To Java Regular Expressions API | Baeldung
January 8, 2024 - We obtain a Matcher object by invoking the matcher method on a Pattern object. PatternSyntaxException object is an unchecked exception that indicates a syntax error in a regular expression pattern. We’ll explore these classes in detail; however, we must first understand how to construct a regex in Java...
🌐
GeeksforGeeks
geeksforgeeks.org › java › regular-expressions-in-java
Regular Expressions in Java - GeeksforGeeks
May 22, 2026 - Use Pattern.compile() to create a regex pattern. Use matcher() on a Pattern to perform matches.
Find elsewhere
🌐
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 - Regular Expressions in Java A regular expression is essentially a search pattern defined by a sequence of characters. While String methods like contains(), startsWith(), or indexOf() are great for …
🌐
Baeldung
baeldung.com › home › java › java string › get the indexes of regex pattern matches in java
Get the Indexes of Regex Pattern Matches in Java | Baeldung
January 8, 2024 - Consequently, these methods provide the starting and ending indexes corresponding to the matched content within the corresponding group: Pattern pattern = Pattern.compile("<([^>]*)>"); Matcher matcher = pattern.matcher(INPUT); List<String> result ...
🌐
JRebel
jrebel.com › blog › java-regular-expressions-cheat-sheet
Java Regular Expressions (Regex) Cheat Sheet | JRebel
July 30, 2025 - A noteworthy combination of the boundary matchers is the "^pattern$" which will only match the text if it is the full pattern.Back to top · Now we’re getting into more advanced territory. If a pattern is more than a single character long, it will match a longer string too. In general "XY" in the Regex Java syntax matches X followed by Y.
🌐
GeeksforGeeks
geeksforgeeks.org › java › matcher-pattern-method-in-java-with-examples
Java Matcher pattern() Method - GeeksforGeeks
July 11, 2025 - Example 1: The below example demonstrates how the pattern() method retrieves the regex pattern "G.*s$" used to match a string ending with "s" and starting with "G". ... // Java code to illustrate pattern() method import java.util.regex.*; public ...
🌐
Medium
medium.com › javarevisited › making-regex-your-friend-in-java-ddc5bf7f9a66
Tutorial on how regex works in Java | Javarevisited
September 21, 2021 - In other words, you’re telling the regex to “match against my regex, but save these sub-results for me”. Let’s look at an example. Here we are trying to match a string of the format: DIGIT+DIGIT=DIGIT. And we want to extract the digits.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › regex › Matcher.html
Matcher (Java Platform SE 8 )
July 21, 2026 - Once created, a matcher can be used to perform three different kinds of match operations: The matches method attempts to match the entire input sequence against the pattern. The lookingAt method attempts to match the input sequence, starting at the beginning, against the pattern.
🌐
Mkyong
mkyong.com › home › java › java regular expression examples
Java Regular Expression Examples | mkyong.com
July 18, 2019 - package com.mkyong.regex; import java.util.Arrays; import java.util.List; public class JavaRegEx2 { public static void main(String[] args) { List<String> numbers = Arrays.asList("1", "20", "A1", "333", "A2A211"); for (String number : numbers) { System.out.println(number.replaceAll("\\d", "#")); } // Java 8 stream example numbers.stream() .map(x -> x.replaceAll("\\d", "#")) .forEach(System.out::println); } } ... package com.mkyong.regex; import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class JavaRegEx3 { public static void main(String[] args) { List<String> numbers = Arrays.asList("1", "20", "A1", "333", "A2A211"); Pattern pattern = Pattern.compile("\\d+"); for (String number : numbers) { Matcher matcher = pattern.matcher(number); while (matcher.find()) { System.out.println(matcher.group(0)); } } } }
🌐
W3Schools
w3schools.com › java › java_switch.asp
Java Switch
Instead of writing many if..else statements, you can use the switch statement.
🌐
RegExr
regexr.com
RegExr: Learn, Build, & Test RegEx
Supports JavaScript & PHP/PCRE RegEx. Results update in real-time as you type. Roll over a match or expression for details. Validate patterns with suites of Tests. Save & share expressions with others. Use Tools to explore your results. Full RegEx Reference with help & examples.
🌐
GeeksforGeeks
geeksforgeeks.org › java › matcher-class-in-java
Matcher Class in Java - GeeksforGeeks
January 27, 2026 - The Matcher class provides methods ... public class GFG { public static void main(String[] args) { Pattern pattern = Pattern.compile("java"); Matcher matcher = pattern.matcher("java is java"); System.out.println(matcher.find()); } }...
🌐
Jenkov
jenkov.com › tutorials › java-regex › index.html
Java Regex - Java Regular Expressions
March 5, 2019 - For instance, the following example ... index 0: String text = "Line 1\nLine2\nLine3"; Pattern pattern = Pattern.compile("^"); Matcher matcher = pattern.matcher(text); while(matcher.find()){ System.out.println("Found match at: " + matcher.start() + " to " + matcher.end()); }...
🌐
C# Corner
c-sharpcorner.com › article › regex-in-java
How to use Regex in Java
September 5, 2023 - The matches method is used to check whether the pattern string matches with the matcher string or not. It returns the boolean value. If the string matches, it returns true otherwise false. It does not take any argument. It does not throw any exception. ... The complete program of java.util.regex.Matcher.matches() method is listed below.
🌐
Softhints
softhints.com › java-regex-matcher-example
java regex matcher example - Softhints
July 18, 2023 - import java.util.regex.Matcher; ... { System.out.println(matchDate.group()); } result: 10/10/2015 10/10/2018 · First example of extracting date of format dd MMM yyyy....