Skip to content
Advertisement

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 basically surrounds the regex with the pair of Q and

Regex for adding a word to a specific line if line does not contain the word

I have a YAML file with multiple lines and I know there’s one line that looks like this: Note that there is unknown number of whitespaces at the beginning of this line (because YAML). The line can be identified uniquely by the schemas: expression. The number of existing values for the schemas property is unknown, but greater than zero. And

Regex for letters and numbers with any underscores in between

I’m trying to create a Regex String with the following rules The username is between 4 and 25 characters. It must start with a letter. It can only contain letters, numbers, and the underscore character. It cannot end with an underscore character. when it meets this criterion I want the output to be true otherwise false, but I only get

Regular expression in java for matching string not enclosed in single quote

I’m parsing my scripts for wrong strings and have an array list with strings that shouldn’t occur in my lines of code. But some strings should pass when they are not exactly the string. Examples: list contains “FOO” and “BAR” textlines: result I’ve tried a view examples I found online and on stackoverflow but these didn’t work for me, they

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’re removing any non-Latin characters in the first regex then we

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 lookahead conditions: RegEx Demo RegEx Details: b: Word boundary

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 modify it to make it work? Edit 1: The following code should

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

Advertisement