Skip to content
Advertisement

Tag: regex

Java equivalent of this JavaScript regex code?

I have this JavaScript code: I am trying to find the Java equivalent. I’ve tried the following bit it gives a different result: Any help is much appreciated! Answer The problem you are having is that ‘\$&’ is Javascript mean whole matched string but doesn’t mean the same in Java. I don’t think there is a one-line solution in Java

ANTLR4: How to match extra spaces at the beginning of a line?

I tried to match the extra space at the beginning of the line, but it didn’t work. How to modify the lexer rule to match? TestParser.g4: TestLexer.g4: Text: Java code: The output is as follows: The idea is that when a non-option line is encountered in OPTION_MODE, the mode will pop up, and now when there is an extra space

Regex match all text after dash

I try to get all text after hyphen (dash). For example, if I have a text like this: I need to get text. I tried this: But it matches all text after dash with that dash and I need to get just text. Answer You can remove all text before the first occurrence of a hyphen and the hyphen(s) right

Java Regex Handling

Looking for a java regex function to 1 – return true if Special characters present before or after from my list of array elements 2 – Return False if any alpha characters present before and after from my list of array elements My array elements wordsList = {“TIN”,”tin”} Input: 1-CardTIN is 1111 2-Card-TIN:2222 3-CardTINis3333 4-Card@TIN@4444 5-CardTIN@5555 6-TINis9999 Expected Output: 1-True

Regex for extracting all heading digits from a string

I am trying to extract all heading digits from a string using Java regex without writing additional code and I could not find something to work: “12345XYZ6789ABC” should give me “12345”. “X12345XYZ6789ABC” should give me nothing Answer Use a word boundary b: See live demo. If you strictly want to match only digits at the start of the input, and

Parsing multiple JSON objects that exist in one line in Java

I’m currently using the OMDB API, which can either return get-queries as JSON objects or XML. Working with JSON is something I’d like to learn, and it generally seems like best solution for what I’m trying to do. The implementation I’m hoping for, is to allow the user to search for a movie, and select the correct one from a

Unclosed character class while replacing string with regex

I want to remove a string at the beginning of another. Example: Begin Removed Final “n123 : other” Yes other “123 : other” No Error “n4 : smth” Yes smth “123 : a” No Error Thanks to Regexr, I made this regex: I tried to use it in Java. With string.matches() I don’t have any error. But, with string.replaceFirst, I

Advertisement