Home > other >  The regular expression the asterisk
The regular expression the asterisk

Time:09-22

Could you tell me why the print (re search (' ABC * ', 'abcdefg)) and print (re) search (' ABC. * g', 'abcdefg)) can match
And print (re search (' ABC * g ', 'abcdefg)) but this does not match

CodePudding user response:

'ABC * g'
Refers to any number of ABC behind c, c can be 0 to any one, the first 'is actually matches the ABC, ABC * instead of abcdefg

CodePudding user response:

Print (re. Search (' ABC * ', 'abcdefg)) and print (re) search (' ABC. * g', 'abcdefg)) matching
Print (re. Search (' ABC * g ', 'abcdefg)) does not match the

===========
This is to belong to the basic rules for regular expression!
* represents any (may be zero, one or more)
Number to represent any character.

'ABC * g' representatives can be: abg, abcg, abccg, ABC... CG
So and 'abcdefg mismatch is normal!

CodePudding user response:

Re search (' ABC. * g ', 'abcdefg')
Is the cause of the match ". "represents all of the characters, and matches from D to F, in fact not G also can match, or the use of the *
  • Related