I would like to find a string that starts and ends with a specific special character but skipping when another specific charachter. I want to find any string that starts with “hello”and ends with a dot “.” but not like “here end.” this must be skipped when “here end” is preceding the dot “.”. Sample : I tried the following
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 – recognise clusters of numbers and characters but only match a part with numbers
I want to write a regex that extracts numbers that might be related to age. It should recognise both simple ‘forms’ as 98, 1, 25 and more complex like 90-years-old. However, in case of more complex forms, I would like it to only match a number. I will later check if it concerns the age, but this is irrelevant for
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
Check String against list of characters and replace it dynamically – Regex
I’m trying to find a solution for this matter. I have list of characters that needs to be replaced with particular character that is mapped with the original character. Ex : I have character map which hold the characters and it’s replacement value. Character Map : String that needs to be replaced : String hello = “Hello& World^”; I want
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