Skip to content
Advertisement

Tag: regex

Partial Matching of Regular Expressions

In NFA it is easy to make all previously non-final states accepting to make it match language of all substrings of a given language. In Java regex engine, is there a way to find out if a string is a starting substring of a string that matches given regex? expression regexX ~ “any start of”, regexA = any normal regex

Use pattern in getAttribute in NiFi

How can I use a pattern in getAttribute of a FlowFile? I’m going to write a processor that receives flowfiles from ListenTCP and ListenUDP processors. ListenTCP has tcp.sender property and ListenUDP has udp.sender property. How can I get the sender property of a FlowFile? The current solution is: How can I avoid using if? I need something like this: Answer

Regex Pattern with Unicode doesn’t do case folding

In C# it appears that Grüsse and Grüße are considered equal in most circumstances as is explained by this nice webpage. I’m trying to find a similar behavior in Java – obviously not in java.lang.String. I thought I was in luck with java.regex.Pattern in combination with Pattern.UNICODE_CASE. The Javadoc says: UNICODE_CASE enables Unicode-aware case folding. When this flag is specified

Mapping SQL NUMERIC[10,0] to java type

I need to map NUMERIC[10,0] parameter type of a sybase stored procedure to a java type. What would be this type? Also, if you can help me define a regular expression for this NUMERIC[10,0] type I’ll be greatful. Answer Use Long as Integer is to short to map all possible values. Have a look at MAX_VALUE of both types.

Regex for polynomial expression

I have a string that I hope is a polynomial expression, something like “2x^2-3x+1. I want to use a regex to group each term in the expression. I currently have “^(-?d?x(^d)?)+”. I’m trying to capture a term as an optional minus sign, then a number, then x, then an optional exponent, which should be of the form “^someNumber”. So for

Java: Extracting a specific REGEXP pattern out of a string

How is it possible to extract only a time part of the form XX:YY out of a string? For example – from a string like: sdhgjhdgsjdf12:34knvxjkvndf, I would like to extract only 12:34. ( The surrounding chars can be spaces too of course ) Of course I can find the semicolon and get two chars before and two chars after,

Unique regex for first name and last name

I have a single input where users should enter name and surname. The problem is i need to use checking regEx. There’s a list of a requirements: The name should start from Capital Letter (not space) There can’t be space stacks It’s obligate to support these Name and Surname (all people are able to write theirs first/name). Example: And the

Are non-capturing groups redundant?

Are optional non-capturing groups redundant? Is the following regex: semantically equivalent to the following regex? Answer Your (?:wo)?men and (wo)?men are semantically equivalent, but technically are different, namely, the first is using a non-capturing and the other a capturing group. Thus, the question is why use non-capturing groups when we have capturing ones? Non-caprturing groups are of help sometimes. To

Differences between W, \W, [^a-zA-Z0-9_] in regular expression

I am trying to find all characters, which are not letters(upper/lowercase), numbers, and underscore, and remove it. However, the following code could not even compile in Java: If I use only “\W” rather than “W”, the above code turns out to be correct. So, what is the differences between W, \W, and when to use brackets like [^a-zA-Z0-9_] Answer However,

Advertisement