I've to match this pattern:
3BxFxxx131xxxx
Where "x" stand for a character that is not needed to be matched.
Is possibile to match a string with this pattern?
I'm forced to use a concatenaion of "/^.{2}B/" for every position or exist a better solution?
Thank you
As per your comment, "x" stands for any alphanumeric char. In that case you could try:
^(?!.*_)3B\wF\w{3}131\w{4}$
See the online demo
^ - Start string anchor.
(?!.*_) - Negative lookahead to prevent underscore anywhere in the string.
3B - Match "3B" literally.
\w - A single word-character. Shorthand for [0-9A-Za-z_].
F - Match "F" literally.
\w{3} - Three word-characters.
131 - Match "131" literally.
\w{4} - Four word-characters.
$ - End string anchor.
Related
Using Regex, I want to match any URL that includes the /it-jobs/ but must have something after the final /.
To be a match the URL must have /it-jobs/ + characters after the trailing / otherwise it should not match. Please refer to below example.
Example: www.website.com/it-jobs/ - is not a match
www.website.com/it-jobs/java-developer - is a match
www.website.com/it-jobs/php - is a match
www.website.com/it-jobs/angular-developer - is a match
You can use
/it-jobs/[^/\s]+$
To match the whole string, add .* at the pattern start:
.*/it-jobs/[^/\s]+$
See the regex demo.
Details:
.* - zero or more chars other than line break chars as many as possible
/it-jobs/ - a literal string
[^/\s]+ - any one or more chars other than / and whitespaces
$ - end of string.
I want to write a regex pattern to match a string starting with "Z" and not containing the next 2 characters as "IU" followed by any other characters.
I am using this pattern but it is not working Z[^(IU)]+.*$
ZISADR - should match
ZIUSADR - should not match
ZDDDDR - should match
Try this regex:
^Z(?:I[^U]|[^I]).*$
Click for Demo
Explanation:
^ - asserts the start of the line
Z - matches Z
I[^U] - matches I followed by any character that is not a U
| - OR
[^I] - matches any character that is not a I
.* - matches 0+ occurrences of any character that is not a new line
$ - asserts the end of the line
When you want to negate certain characters in a string, you can use character class but when you want to negate more than one character in a particular sequence, you need to use negative look ahead and write your regex like this,
^Z(?!IU).*$
Demo
Also note, your first word ZISADR will match as Z is not followed by IU
Your regex, Z[^(IU)]+.*$ will match the starting with Z and [^(IU)]+ character class will match any character other than ( I U and ) one or more times further followed by .* means it will match any characters zero or more times which is not the behavior you wanted.
Edit: To provide a solution without look ahead
A non-lookahead based solution would be to use this regex,
^Z(?:I[^U]|[^I]U|[^I][^U]).*$
This regex has three main alternations which incorporate all cases needed to cover.
I[^U] - Ensures if second character is I then third shouldn't be U
[^I]U - Ensures if third character is U then second shouldn't be I
[^I][^U] - Ensures that both second and third characters shouldn't be I and U altogether.
Demo non-look ahead based solution
I have implemented the following Regex pattern
^[\d,|+\d,]+$
It validates the following pattern
14,+96,4,++67
I need to invalidate ++67 from my pattern and I need to keep values with only a single leading + sign.
How should I change my Regex pattern?
You may use
^\+?\d+(?:,\+?\d+)*$
See the regex demo.
Details
^ - start of string
\+? - an optional + char
\d+ - 1+ digits
(?:,\+?\d+)* - zero or more repetitions of a sequence of patterns:
, - a comma
\+? - an optional plus
\d+ - 1+ digits
$ - end of string
Perhaps you meant to do this?
^(\d,|\+\d,)+$
Square brackets use every character or character class within, which does not appear to be what you really want. For disjunction you need round brackets.
You can try this one
^(\d+\,?|\+\d+,?)+$
I broke it down to two, but I'm wondering if it's possible in one.
My two regex
/^[^\s+ ]+$/
/(.*[a-zA-Z].*)/
You can use
/^[^+\s]*[a-z][^+\s]*$/i
See the regex demo
The pattern matches:
^ - start of string
[^+\s]* - zero or more characters other than + and whitespace
[a-z] - a letter (case insensitive - see /i modifier)
[^+\s]* - zero or more characters other than + and whitespace
$ - end of string
This expressions only requires one letter, and there can be any number of characters other than a space and a plus on both sides of the letter.
Try this. I'm not sure what you mean by "unique", though:
/^[^+\s]*[A-Za-z][^+\s]*$/
Why not both?
^(?=.*[a-zA-Z])[^\s+]+$
Uses lookahead.
^(?=.*[a-zA-Z])[^\s+]+$
^ start of regex
(?=.*[a-zA-Z]) make sure there is at least a letter ahead
[^\s+]+ make every character is not a plus or any whitespace character
$ end of regex
Notice how I changed your [^\s+ ] into my [^\s+] because \s already included the space (U+0020).
I'm fairly new to regex. I'm looking for an expression which will return strings in which the first character is of length 1, followed by an unlimited number of words of length 3 or more.
There should be a space between each word+.
So far I have:
([A-Za-z]{1,1} [A-Za-z+]{3,100})
As it stands this only returns phrases such as:
'I will' and 'A bird'
But I would like it to return phrases like:
'I will always try' and 'A bird flew into the cage'
Any help would be appreciated. I'm using an application called 'Oracle EDQ'.
You need to apply the limiting quantifier {3,} to the [A-Za-z] group and the * (zero or more repetitions) to the outer group matching a space + the 3+-letter words:
^[A-Za-z]( [A-Za-z]{3,})*$
See regex demo. Note the use of anchors ^ and $ that is very important when you need to match characters at a specific place (here, at the start and end of a word).
Regex matches:
^ - checks the regex engine is at the beginning of a string
[A-Za-z] - Exactly 1 letter a to z and A to Z
( [A-Za-z]{3,})* - zero or more sequences of...
- a space
[A-Za-z]{3,} - 3 or more ASCII letters
$ - end of string.
You can use this regex:
^[A-Za-z](?: [A-Za-z]{3,})+$
RegEx Demo