Regex 4 characters and 1 space minimum anywhere position - regex

I've tried this
(?!\sa-zA-Z){4,}\s{1,}
I want 4 or more characters and minimum 1 space anywhere in string, but doesn't work
The space can be anywhere position without from start.
I've try this, but that not work
Regex: Allow minimum alphanumeric, dot and - characters. Asterisk allowed anywhere?
EDIT: I would like this result :
aa aa..., aaa a..., a aaa..., aaaa ...

You can use
\b[a-zA-Z](?=[a-zA-Z ]{3})[a-zA-Z]* +[a-zA-Z]*
Explanation
\b A word boundary to prevent a partial word match
[a-zA-Z] Match a single char a-zA-Z
(?=[a-zA-Z ]{3}) Positive lookahead, assert 3 of the listed chars in the character class to the right of the current position
[a-zA-Z]* +[a-zA-Z]* Match optional chars a-zA-Z, then match 1+ spaces space and again optional chars a-zA-Z
See a regex demo.

Related

How do I include characters, space and maximum two consecutive character in dart?

Does anyone know how to use a regular expression in Dart, where maximum two consecutive characters allow.
Example :
aabc //allow
aaabc // not allow
aabc aabc // not allow same string
aabcde //allow
abs cdd ert fgg fgy df //allow
I tried this but it won't work:
([A-Za-z])?!.*\1
([a-zA-Z])-?\1-?\1-?\1-?\1
^(?:([A-Za-z])(?!.\1))$
If you want to match chars A-Za-z, you can make use of word boundaries and use 2 negative lookaheads.
The first lookahead excludes matching 3 of the same chars in a row, the second lookahead excludes 2 times the same "word" where a word is identified by the word boundaries.
^(?!.*([A-Za-z])\1\1)(?!.*\b([A-Za-z]+)\b.*\2).+
Explanation
^ Start of string
(?!.*([A-Za-z])\1\1) Negative lookahead, assert that to the right is not a char A-Za-z directly followed by 2 times the same char using a backreference
(?!.*\b([A-Za-z]+)\b.*\2) Negative lookahead, assert that to the right is not 1+ chars A-Za-z surrounded by a word boundary, and then find that same "word" again
.+ Match 1+ chars
See a regex demo.

What is the Regex pattern "words with numbers in them" but not a number itself

How does a regex look like for
Input:
Rood Li-Ion 12 G6
Match:
"Rood" "Li-Ion" "G6"
1.
I tried
\b[\w-]+\b /g
But that matches the "12" also!
2.I tried
/([0-9]+)?[a-zA-ZĂȘ]/
But that didn't match G6.
I want all words even if they have a number in them but I dont want only numbers to match. How is this possible. Whitespace also shall not be part of the match.
"Rood Li-Ion 12 G6" shall become 3 strings of "Rood","Li-Ion","G6"
You can use
(?<!\S)(?!\d+(?!\S))\w+(?:-\w+)*(?!\S)
See the regex demo. It matches strings between whitespaces or start/end of string, and only when this non-whitespace chunk is not a digit only chunk.
Also, it won't match a streak of hyphens as your original regex.
Details
(?<!\S) - a left whitespace boundary
(?!\d+(?!\S)) - no one or more digits immediately to the right capped with whitespace or end of string is allowed
\w+(?:-\w+)* - one or more word chars followed with zero or more repetitions of - and one or more word chars
(?!\S) - a right whitespace boundary
This should suit your needs:
\b[\w-]*[a-zA-Z][\w-]*\b

Regex match checksum with or without dashes

To match a dash-less checksum I can do something like:
\b[0-9a-z]{32}\b
However, I'm seeing some checksums that also have dashes, such as:
d3bd55bf-062f-473b-9417-935f62c4c98a
While this is probably a fixed size, 8, then 4, then 4, then 4, then 12, I was wondering if I could do a regex where the number of non-dash digits adds up to 32. I think the answer is no, but hopefully some regex wizard can come up with something.
Here is a starting point for some sample inputs: https://regex101.com/r/K0IMKe/1.
You can use
\b[0-9a-z](?:-?[0-9a-z]){31}\b
See the regex demo.
It matches
\b - a word boundary
[0-9a-z] - a digit or a lowercase ASCII letter
(?:-?[0-9a-z]){31} - thirty-one repetitions of an optional - followed with a single digit or a lowercase ASCII letter
\b - a word boundary.
If you do not mind having a trailing - if there is a word char after it, at the end of a match, you may also use
\b(?:[0-9a-z]-?){32}\b
See this regex demo. Here, (?:[0-9a-z]-?){32} will match thirty-two repetitions of a digit or lowercase ASCII letter followed with an optional hyphen.
If there can be multiple dashes, you can assert 32 to 36 chars using a positive lookahead.
^(?=[a-z0-9-]{32,36}$)[a-z0-9]+(?:-[a-z0-9]+)*$
^ Start of string
(?=[a-z0-9-]{32,36}$) Positive lookahead, assert what is at the right is 32 - 36 repetitions of the listed characters
[a-z0-9]+ Match 1+ times any of the listed
(?: Non capture group
-[a-z0-9]+ Match a - followed by 1+ times any of the listed (the string can not end with a hyphen)
)* Close the group and match 0+ times to also match the string without dashes
$ End of string
Regex demo
If you want to limit the amount of dashes to 0 -4 times, you can change the quantifier * to {0,4}+
^(?=[a-z0-9-]{32,36}$)[a-z0-9]+(?:-[a-z0-9]+){0,4}+$
Regex demo

How can I fix this negative lookahead to make it work

I have a string for example as follows:
ABCD17; ABC18; ABCEF19; XYZ19; ABCDE
Within the MusicBee application, I'm attempting to use a Regex replace function to swap MATCHED items for blanks and thus transform the above string into
ABCEF19; XYZ19
i.e. ONLY retain the items ending in "19"
The elements can be any length and they may or may not end in a number.
The following expression correctly matches the items Ending in 19
[^|;].*(?=19).{3}
However, I obviously need the opposite of this (since the matched items are then replaced with empty strings) which is NOT (surprisingly to me)
[^|;].*(?!19).{3}
If you only want to keep items that end on 19, one option might be to use word boundaries \b and start matching 1+ uppercase chars A-Z.
Optionally match the digits at the end when it is not 19 using the negative lookahead (?!19\b)
\b[A-Z]+(?!19\b)\d*\b;?
\b Word boundary
[A-Z]+ Match 1+ uppercase chars A-Z (or use [^\W\d] to match word chars without a digit)
(?!19\b) Negative lookahead, assert what is directly on the right is not 19
\d* Match 0+ digits
\b;? Word boundary and optionally match ;
Regex demo

Regex to exclude alpha-numeric characters

I thought [^0-9a-zA-Z]* excludes all alpha-numeric letters, but allows for special characters, spaces, etc.
With the search string [^0-9a-zA-Z]*ELL[^0-9A-Z]* I expect outputs such as
ELL
ELLs
The ELL
Which ELLs
However I also get following outputs
Ellis Island
Bellis
How to correct this?
You may use
(?:\b|_)ELLs?(?=\b|_)
See the regex demo.
It will find ELL or ELLs if it is surrounded with _ or non-word chars, or at the start/end of the string.
Details:
(?:\b|_) - a non-capturing alternation group matching a word boundary position (\b) or (|) a _
ELLs? - matches ELL or ELLs since s? matches 1 or 0 s chars
(?=\b|_) - a positive lookahead that requires the presence of a word boundary or _ immediately to the right of the current location.
change the * to +
a * means any amount including none. A + means one or more. What you probably want though is a word boundry:
\bELL\b
A word boundry is a position between \w and \W (non-word char), or at the beginning or end of a string if it begins or ends (respectively) with a word character ([0-9A-Za-z_]). More here about that:
What is a word boundary in regexes?