+ 7
[SOLVED] Why this is returning false?
Here's the code link: https://code.sololearn.com/WMDQHz9b3R0z/?ref=app
13 Answers
+ 9
because /re*ex/ search for 'r' followed by 0 or more 'e', then followed by 'ex'...
instead try /re.*ex/ wich search for 're' followed by 0 or more any char, then followed by 'ex' ;)
+ 5
âKĂȘsh@v
Use the "." And "*" together
Like
/re.*ex/
it will find any number occurance of any character including 0 occurance after "re"
+ 4
âKĂȘsh@v
n* Matches any string that contains zero or more occurrences of n
Means re*ex
Will match reex (0 occurance of e)
Will match reeex (1 occurance of e)
Another example
Ar*av
Will match Arav (0 occurance of r)
Will match Arrav (1 occurance of r)
And so on
if there would be any other characters other than the character that is precided by * it will not match
+ 4
âKĂȘsh@v yeah
+ 3
visph Thanks for your response
But would you please elaborate in a better way? I didn't got you đ
+ 3
Arnav Kumar Yea I tried and it worked fine
But needs explaination, why it's not working with only asterisk.
The tutorial video I watched on YouTube, it was working fine there.
+ 2
Assassin
Period (.) symbol is used for only one character
But if we use asterisk (*) here, it will be able to find match for more than one characters
+ 2
Arnav Kumar Oh I see!!
It means the every character should be the same in place of asterisk?
Edit:-
reeeeeeeex // true
reeeeegex // false
+ 2
Assassin no no đ
+ 2
visph Arnav Kumar
Now I understand that!
Thanks for the clarification đ
+ 1
* apply to the previous character (or group) in the regex pattern:
/re*ex/
will match 'rex' (0 occurences of first e), 'reex' (1 occurence), 'reeex' (2 occurences)... and so on...
. match any character, .* match 0 or more any character:
/re.*ex/
will match 'reex' (0 occurences), 'regex' (1 occurence), 'reflex' (2 occurences)... and so on...