Skip to content

Tag: regex

Java PathMatcher not working properly on Windows

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

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 …

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…

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

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}(?:(?=([.,…