Every time this is asked, the answer is to use negative lookahead like so: (?!x)
Well unfortunately I must implement an American Express check in vb6, which does NOT support negative lookaheads or negative look behinds.
Is it possible to match everything except 34, 37 using the oldest imaginable implementation of regular expressions?
I expected this sort of thing to work:
^[1,2,4-9][1-3,5-6,8-9][0-9]{13}$
I've been able to match AmEx with this expression of course: ^3[47][0-9]{13}$ but I haven't found a way to inverse the validation rule.
Here is my validator setup:
<asp:RegularExpressionValidator
ID="AmExValidator"
Display="None"
ControlToValidate="txtCreditCardNumber"
ValidationExpression="^[1,2,4-9][1-3,5-6,8-9][0-9]{13}$"
ErrorMessage="American Express cards are not accepted."
ValidationGroup="Payment"
runat="server">
</asp:RegularExpressionValidator>```
You can use
^([0-24-9][0-9]|3[0-35689])[0-9]{13}$
See the regex demo. Details:
^ - start of string
([0-24-9][0-9]|3[0-35689]) - 00 to 29 and 40 to 99, or 3 followed with a digit other than 4 and 7
[0-9]{13} - thirteen digits
$ - end of string.
Related
Let's say that we have this text:
2020-09-29
2020-09-30
2020-10-01
2020-10-02
2020-10-12
2020-10-16
2020-11-12
2020-11-23
2020-11-15
2020-12-01
2020-12-11
2020-12-30
I want to do something like this:
\d\d\d\d-(NOT10)-(30)
So i want to get all dates of any year, but not of the 10th month and it is important, that the day is 30.
I tried a lot to do this using negative lookahead asserations but i did not come up with any working regexes.
You can use negative lookaheads:
\d\d\d\d-(?!10)\d\d-30
The Part (?!10) ensures that no 10 follows at the point where it is inserted into the regex. Notice that you still need to match the following digits afterwards, thus the \d\d part.
Generally speaking you can not (to my knowledge) negate a part that then also matches parts of the string. But with negative lookaheads you can simulate this as I did above. The generalized idea looks something like:
(?!<special-exclusion-pattern>)<general-inclusion-pattern>
Where the special-exclusion-pattern matches a subset of the general-inclusion-pattern. In the above case the general inclusion pattern is \d\d and the special exclusion pattern ins 10.
Try :
/20\d{2}-(?:0[1-9]|1[12])-30/
Explanation :
20\d{2} it will match 20XX
(?:0[1-9]|1[12]) it will match 0X or 11, 12
30 it will match 30
Demo :https://regex101.com/r/O2F1eV/1
It's easiest to simply convert the substring (if present) that matches /^\d{4}-10-30$/ to an empty string, then split the resulting string on one or more newlines.
If your string were
2020-10-16
2020-10-30
2020-11-12
2020-11-23
and was held by the variable str, then in Ruby, for example,
str.sub(/^\d{4}-10-30$/,'')
#=> "2020-10-16\n\n2020-11-12\n2020-11-23\n"
so
str.sub(/^\d{4}-10-30$/,'').split
#=> ["2020-10-16", "2020-11-12", "2020-11-23"]
Whatever language you are using undoubtedly has similar methods.
I use a regular expression to validate a Dutch mobile phone number:
^((\+316|06|00316){1}\\s?-?\s?[1-9]{1}[0-9]{7})$
So the number should start with 06 or +316 or 00316 followed by 8 digits (not starting with a 0)
Now I have to extend the validation so it also allows for international numbers from outside The Netherlands.
I want to keep it simple so I was thinking:
If it not starts with 06 or +316 or 00316 then it should start with '00dd' or '+dd' where dd!=31 followed by 8 till 12 digits.
so 0032127384562 should match but 00317198765432 not (because it starts with 0031 but not 00316)
Does anybody know how to do this?
The regex for the international number is:
^00(?!31)[0-9]{2}\s?-?\s?[1-9][0-9]{7,11}$
or, if you can't use lookahead:
^00([0-24-9][0-9]|3[02-9])\s?-?\s?[1-9][0-9]{7,11}$
You can concatenate it with | and the Dutch regex.
Be aware that there is a typo in your regex at \\.
My regex currently looks like this
\b(19|20)\d{2}\b[- :][VW][0-5]{1}(?(?=[5])[0-2]{1}|[0-9]{1})
It doesn't quite do what I want as I'm trying to get this part
(?(?=[5])[0-2]{1}|[0-9]{1})
to say "If the previous number was 5 then you may only choose between 0-2, and if it's another number 0-4 then choosing between 0-9 is allowed
Currently it allowes 00-59 with an exclusion of 05,15,25,35 etc.
Essentially I want it to look like this for example 2016-W25.
You need to replace [5] with a positive lookbehind (?<=5) in order to check a char to the left of the current location:
\b(19|20)\d{2}[- :][VW][0-5](?(?=(?<=5))[0-2]|[0-9])
^^^^^
See the regex demo
Also, you may get rid of the conditional pattern at all using a mere alternation group:
\b(19|20)\d{2}[- :][VW](?:[0-4][0-9]|5[0-2])
^^^^^^^^^^^^^^^^^^^^^
See this regex demo
The (?:[0-4][0-9]|5[0-2]) matches either a digit from 0 to 4 and then any digit (see [0-4][0-9]), or (see |) a 5 followed with 0, 1 or 2 (see 5[0-2]).
NOTE: Since the number of weeks can amount to 53, the [0-2] at the end might be replaced with [0-3] to also match 53 values.
Hello I should think of this regular expression:
The telephone number should begin with 087 OR 088 OR 089 and then it should be followed by7 digits:
This is what I made but it doesn't work correctly: it accepts only numbers which begin with 089
(087)|(088)|(089)[0-9]{7}";
/08[789]\d{7}/
that will match 087xxxxxxx, 088xxxxxxx, 089xxxxxxx numbers.
See it in action
Maybe /08[7-9][0-9]{7}/ is what you're searching for?
Autopsy:
08 - a literal 08
[7-9] - matches the numbers from 7-9 once
[0-9]{7} - matches the numbers from 0-9 repeated exactly 7 times
That said, you might prefer /^08[7-9][0-9]{7}$/ if your string is only the phone number. (^ means "the string MUST start here" and $ means "the string MUST end here").
Actually that will be far better regex for Bulgarian phone numbers:
/(\+)?(359|0)8[789]\d{1}(|-| )\d{3}(|-| )\d{3}/
It checks:
Phones that start with country code(+359) or 0 instead;
if the phone number use delimiters like - or space.
I tried it in https://regex101.com and it did not work against my test set. So I tweaked it a little bit with the below regex pattern:
^([+]?359)|0?(|-| )8[789]\d{1}(|-| )\d{3}(|-| )\d{3}$
I have a regex that looks like this
((1010xxx)?(\d{11}|\d{10}|\d{7})+)
Basically I want it to match
8085551234
5551234
10102338085551234
and it should fail on
1010233
This is more for validation being done on an xsd than an actual matcher.
PS.
I am trying to match US telephone numbers 7 - 11 digits long with an optional 1010xxx at the front. Also if it is 1010xxx it should not pass. xxx is any 3 digits.
If all you want is to make sure that it's a 7, 10, or 11 digit string, making sure that if it's only 7 digits it doesn't start with '1010', you can use a negative lookahead assertion before your match on \d{7}, i.e.:
((\d{11}|\d{10}|(?!1010)\d{7})+)