I am trying to create a regex that detect if a string of hexadecimal is only a combination of 00 , 06, 03 and space.
The closest i've found so far is ^(00|06|03)$ but it's still giving me false for 0300
0300 will match
0600 0300 match
0612 0300 no match
3030 no match
^(00|06|03)$ will only match '00' or '06' or '03'. If you're expecting this combination to repeat, you need to add +.
Try ^(00|06|03| )+$
I've included the space in there as well. This will match your scenarios.
Close, but you need closure and some safe-guarding:
let v = /^((00|06|03){2}\s)*(00|06|03){2}$/;
[
'0300',
'0600 0300',
'0612 0300',
'3030',
'0303 0000',
'0630 0300',
'8790 0060',
'03 0000',
'0003 0006 0000 0000 0303 0606 0600 0306 0000',
'0606 0603 0303'
].map(s => console.log("%s : %s", s, v.test(s)));
Related
62020180327 00000000000344753973KOLESTON PERF.CAST.MD RAME 4/4PZ2222302620ECU0000073800000099800000000000000000000000000000000 0000 22 2200 KOLESTON
62020180327 00000000000353753976KOLESTON PERF.CAST.CH.DOR. 5/3PZ2222302620ECU0000073800000099800000000000000000000000000000000 0000 22 2200 KOLESTON
62020180327 00000000000357189272KOLESTON PERFECT 5/7 PZ2222302620ECU0000066900000089500000000000000000000000000000000 0000 22 2200ESKOLESTON
62020180327 00000000000373189267KOLESTON PERFECT 7/3 PZ2222302620ECU0000066900000089500000000000000000000000000000000 0000 22 2200ESKOLESTON
hi, I've a list like this one. How could i delete/remove the lines containing the characters ES at postion 141?
Thanks for helping!
Here is the general approach:
Replace this: ^.{140}ES.*(\r?\n|$) with empty string.
Explanation:
^.{140} matches the first 140 characters from the start of the line
ES is the exact match you need
.*(\r?\n|$) matches everything else, including the line break too.
So when you replace everything, including the line break too, then the line disappears. I.e. it doesn't even leave a blank line behind.
I have this Regex to validate Visa and Master card with spaces, it works perfect.
^(?:4\d{3}|5[1-5]\d{2}|6011|3[47]\d{2})([- ]?)\d{4}\1\d{4}\1\d{4}$
Visa
4111111111111111 = true
4111 1111 1111 1111 = true
Master
5500000000000004 = true
5500 0000 0000 0004 = true
American Express
340000000000009 = false
3400 0000 0000 009 = false
I need add Amex to the regex, I need the last two true, can anyone help me please?
Thank you!
(assuming 4111111111111111 = false is a typo)
You can use the following regex :
^(?:4\d{3}|5[1-5]\d{2}|6011|3[47]\d{2})([-\s]?)\d{4}\1\d{4}\1\d{3,4}$
see demo
I do not know the background how you use this regex but i would do this in two steps:
Step 1:
Remove all spaces with one line of code. Since spacing should not define whether a number is valid/invalid.
Step 2:
Use this regex
^(?:4[0-9]{12}(?:[0-9]{3})?|(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|3[47][0-9]{13})$
This catches a few more rules on MasterCards.
Source (Shortend expression since fewer types of cards are needed)
Demo
I'm trying to create a regex to accept digits not starting with zero or a single zero digit.
Example matches
0
50
798
Example rejects
01
046
0014
00
0001
My attempt was to use /[0]|[1-9][0-9]*/ to match the values in the following text:
0, 50, 798
01, 046, 0014, 00, 0001
This attempt can be run at http://regexr.com/3bb00
Use following regex :
^(0|[1-9]\d*)$
see Demo https://regex101.com/r/zT8uI2/2
This regex contains 2 part, 0 or [1-9]\d* which is a digit that doesn't starts with zero.
Note that if you want to match your numbers within other texts you need a word boundary instead of start and end anchors :
\b(0|[1-9]\d*)\b
see demo https://regex101.com/r/zT8uI2/3
It seems that you have two cases in your regex:
Match a single zero
Match digits that don't start with zero.
The first case is easy: /0/
The second case is also pretty easy /[1-9]\d*/. The [1-9] matches the digit that is not 0. Then, we can have 0 or more digits.
To get both of these cases, just use a bar to do either or
/0|[1-9]\d*/
Hmm, why not something like..
if(input[0] == '0' && input.size() > 1) // reject
else //accept
Please check this http://regexr.com/3bb09
Took the tip from https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch06s06.html
and improved it to negate numbers starting with 0.
RE: \b[^0,]*([1-9][0-9]*|0)\b
Text: 0, 50, 798, 01, 046, 0014, 00, 0001
Matched only 0, 50 and 798
Thanks
Venkat
I am studying course for Automata, may be as a beginner I'm missing something , I am really confused with this regular expression as the teacher saying
it represents a language with all binary strings having even number of
symbols
Alphabet Σ={0,1}
((0+1)(0+1))*
(0+1) saying union of 0 and 1
but I am confused here let suppose
first (0+1) gives 01 and second (0+1) gives only 0, then finally we concatenate both having (010)* and let it end up with only one occurrence i.e. 010
then how it has even number of symbols? need little understanding of this...
The given Question: ((0+1)(0+1))*
Let's start from the innermost bracket (0+1) this matches with either 0 or 1 not 01
'+' means "or" operator, this is not a conjunction operator.
and this is repeated twice hence ((0+1)(0+1)) matches with 01 or 10 or 00 or 11
and '*' means it matches 0 or more times
Hence, ((0+1)(0+1))* matches with [NULL] or 01 or 10 or 00 or 11 or 0011 or 1100 or 1010 or 0110 ....so on
Union means one or the other, not both. So, 0+1 would either be 0 or 1, but not both at the same time. Hence (0+1)(0+1) would result in either 00, 01, 10 or 11. All of them have even number of symbols. The result would follow.
I have a small test to match using regex.
Match to true if and only if user has entered "0000" or 000 or 00 or 0.
0001 or 0011, 1000, 0111, 1111 should return false.
Here is what i have tried : /^0*([0]{1,4})/ but it didn't work.
This should work just fine:
/^0{1,4}$/