Skip to content

Tag: regex

replaceFirst , Why can’t special symbols be replaced?

replaceFirst , Why can’t special symbols be replaced? System.out.println(cal); // 1 * 1 + 1 <==== ??? Answer Special symbols which are used in the regular expressions need to be either escaped using or entire expression should be treated as a string literal with the help of Pattern.quote which basic…

Merging 2 regex that allow only English and Arabic characters

I have a string and I want to remove any other character such as (0..9!@#$%^&*()_., …) and keep only alphabetic characters. After looking up and doing some tests, I got 2 regexes formats: This should return “hello مرحبا ok”. But of course, this will return an empty string because we&#821…

Regex to match only 6letter alphanumeric words in a string

I am trying to match the 6 character word that has a combination of ONLY alphanumeric. Example String: I am currently trying regex [a-zA-Z0-9]{6} However, it matches below Output: But, what I need is only combination of alphanumeric. Something like below Desired Output Answer You may use this regex with 2 loo…

Regex to return all subdomains from a given domain

Given a domain string like aaaa.bbbb.cccc.dddd I am trying to iterate over all of its subdomains i.e. I thought this regex ((?:[a-zA-Z0-9]+.)*)([a-zA-Z0-9]+)$ should do the trick (please ignore the fact, that I am only matching these characters [a-zA-Z0-9]), however it only matches the full string. How can I …

Regex match any of the words separated by slashes

I need to develop a validation pattern for catching any kind from: pdf/csv/xlsx select any separate word is simple: (pdf|csv|xlsx). However, I need to check that any combination with them separated by slash is fine as well. For example, correct flow: Incorrect: Answer You may use this regex: RegEx Demo