Reputation: 779
I have a specific requirement to check if all the characters in a string of 8 characters contains repeatition of character '0' I was trying to use regular expression 0{8} to validate for all cases to get result as true - but above regular expression will validate only *
0
00
000
0000
00000
000000
0000000
00000000 ->*
Can anyone suggest if i need to change something in my regular expression to validate all the above inputs ? Appreciate your help.
Upvotes: 1
Views: 74
Reputation: 239
This should be easy with the following.
a = '000000000'
b = '000001000'
a.strip('0') # returns ''
b.strip('0') # returns '1'
For C++
replace( s.begin(), s.end(), '0', '');
Upvotes: 1
Reputation: 425033
To detect any number of repetitions of 0
, simply use:
0+
This matches all your test cases, and of course would match more than 8, but if your input string is max 8 chars, it's OK.
Upvotes: 2