I try to implement a JUnit test for my SimpleFileVisitor but the used PathMatcher doesn’t work properly on Windows. The problem seems to be the PathMatcher with a regex pattern behaves different on Linux and Windows: But I’ve a longer list in my regex for multiple files which are not easy to migrate to glob syntax. Otherwise I’ve nested groups
Tag: regex
Regex to allow space between numbers or nothing before the first one
I have the method that follows – verifyPhones, I am using two regexs on it. The first one is to identify if the String is valid, if not I need to search which numbers are not valid. My problem is when I have two valid numbers together – 20255501252025550125, the system is returning only one of them as wrong instead
Java and regex lexer
I am trying to make some sort of Lexer in Java using regex for a custom markdown “language” I’m making, it’s my first time working with this stuff so a little lost on a few things. An …
How to find if a word immediately followed by a non-letter character exists in a String
I believe the most efficient solution to this issue is to use Regex but I’m uncertain of the syntax. When looking through a sentence, how do you identify if a word followed by a non-letter character (anything other than a,b,c,d,e…) is present in a string. Example below: Answer Use the word boundary regex b, which matches between a letter and
Regular Expression for not allowing two consecutive special characters and also not in beginning and end
I’m looking for a regex for a string to Contain only A-Z a-z 0-9 _ – . Not begin/end with _ – . Not containing consecutive special characters or their combination Max 36 length, minimum 1 Right Wrong: I seearched around and got this :- but this allows all special characters and not just the 3 that i checek Answer
Splitting a string using special characters and keeping them
I’m trying to split a string with special characters and not being able to split the parentheses properly. This the code I’m trying : The regex does not split the starting parentheses ( I’m trying to get the following output: Could someone please help me. Thank you. Answer So you want to use split() to get every character separately, except
Regex to match any number unless it is part of a specific string
Sorry if this is a dupe, I did search but couldn’t seem to find something that matched my query. I have a replacer function in java that runs multiple regexes to find and replace specific strings. One of them is looking at numbers, and if it finds a number it adds space around it, for example; test123 > test 123
Why regex pattern [1-3]\s+[1-3] doesn’t match two numbers separated with whitespaces when used in code
As a part of my project I have a method that checks and returns user input (from console, System.in) if it’s correct (and asks for input again if it’s not). Correct input is a pair of digits between 1 and 3 (inclusively) separated with whitespaces. To check input I’m using hasNext(String pattern) method from class Scanner with regex pattern [1-3]\s+[1-3]
Regular expression to mask email except the three characters before the domain
I am trying to mask email address in the following different ways. Mask all characters except first three and the ones follows the @ symbol. This expression works fine. (?<=.{3}).(?=[^@]*?@) abcdefgh@gmail.com -> abc*****@gmail.com Mask all characters except last three before @ symbol. Example : abcdefgh@gmail.com -> *****fgh@gmail.com I am not sure how to check for @ and do reverse match.
Regular expression in Java for parsing money
I’m looking for are regex for parsing money amounts. The String s10 should not match. Can someone help, or can someone simplify the regex? That’s my try: Answer I think you may use See the regex demo Details (?<![d,.]) – no digit, . or , allowed immediately on the left (?:d{1,3}(?:(?=([.,]))(?:1d{3})*)?|d+) – d{1,3}(?:(?=([.,]))(?:1d{3})*)? – one, two or three digits followed