Skip to content
Advertisement

Tag: regex

Separate definitions of decimal number and word in ANTLR grammar

I’m working on defining a grammar in ANTLR4 which includes words and numbers separately. Numbers are described: and words are described: The simplified grammar below describes the addition between either a word or a letter (and needs to be defined recursively like this): The issue is that when I enter ‘d3’ into the parser, I get a returned instance of

How to properly split on a non escaped delimiter?

I have the following example string: with | being the delimiter and being the escape character. A proper split should look as follows: Also I need this logic to be generally applicable in case the delimiter or the escape consists out of multiple characters. I already have a regex which splits at the correct position, but it does not

Java regex. Keep special characters only when they’re surrounded by numbers

I’m making an word frequency program and I’m trying to process text to make it manageable. I’m trying to remove all special characters except $%^*+-=,./<> which are a part of a number. I have virtually no experience with regular expressions and after reading a bunch on it, I tried using the negative lookadead and negative lookaround to get something like

Java Pattern and Matcher no result

i’m writing this Java program for fun and i’m trying to get groups of substring with a regex. My string is read from a file and it’s something like: t<firstName type=”String”>John</firstName> where t is a tab. I wrote this code to isolate the needed substring, but while on online testing it works, in my code it says “no matches”. My

Advertisement