Skip to content

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…

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”} Inp…

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. …

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 do…