Regular expression to limit number of characters to 10

I am trying to write a regular expression that will only allow lowercase letters and up to 10 characters. What I have so far looks like this: This does not work or compile. I had a working one that would just allow lowercase letters which was this: But I need to limit the number of … Read more

Regular expression to remove HTML tags from a string

You should not attempt to parse HTML with regex. HTML is not a regular language, so any regex you come up with will likely fail on some esoteric edge case. Please refer to the seminal answer to this question for specifics. While mostly formatted as a joke, it makes a very good point. The following examples are … Read more

Difference between regex [A-z] and [a-zA-Z]

[A-z] will match ASCII characters in the range from A to z, while [a-zA-Z] will match ASCII characters in the range from A to Zand in the range from a to z. At first glance, this might seem equivalent — however, if you look at this table of ASCII characters, you’ll see that A-z includes several other characters. Specifically, they are [, \, ], ^, _, and ` (which you clearly don’t want).

How to use regex in String.contains() method in Java

String.contains String.contains works with String, period. It doesn’t work with regex. It will check whether the exact String specified appear in the current String or not. Note that String.contains does not check for word boundary; it simply checks for substring. Regex solution Regex is more powerful than String.contains, since you can enforce word boundary on … Read more

Using regex to match any character except =

I am trying to write a String validation to match any character (regular, digit and special) except =. Here is what I have written – But, it matches the input string “2009-09/09 12:23:12.5=” with the pattern. How can I exclude = (or any other character, for that matter) from the pattern string?

Difference between ?:, ?! and ?=

The difference between ?= and ?! is that the former requires the given expression to match and the latter requires it to not match. For example a(?=b) will match the “a” in “ab”, but not the “a” in “ac”. Whereas a(?!b) will match the “a” in “ac”, but not the “a” in “ab”. The difference … Read more

Extract hostname name from string

I recommend using the npm package psl (Public Suffix List). The “Public Suffix List” is a list of all valid domain suffixes and rules, not just Country Code Top-Level domains, but unicode characters as well that would be considered the root domain (i.e. www.食狮.公司.cn, b.c.kobe.jp, etc.). Read more about it here. Try: Then with my … Read more