Re: [Tutor] What the difference between the two RE?
On 2012/02/09 09:44 AM, daedae11 wrote: However, re.match(hello, And they said hello ) will also return None. So And they said hello also won't be matched by the regex pattern hello. daedae11 *From:* Christian Witts mailto:cwi...@compuscan.co.za *Date:* 2012-02-09 15:16 *To:* daedae11 mailto:daeda...@126.com *CC:* turor_python mailto:tutor@python.org *Subject:* Re: [Tutor] What the difference between the two RE? On 2012/02/09 08:15 AM, daedae11 wrote: import re re.match(^hello, hello) re.match(hello, hello) Please give a string that matches RE ^hello but does not match RE hello, or matches RE hello but does not match RE ^hello. daedae11 ___ Tutor maillist -Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The caret ^ means At the beginning of the line so 'And they said hello' will not be matched by the regex pattern '^hello'. The docs are pretty good on the module http://docs.python.org/library/re.html http://docs.python.org/howto/regex.html -- Christian Witts Python Developer // -- From the docs http://docs.python.org/library/re.html#re.match Note: If you want to locate a match anywhere in string, use search() instead. -- Christian Witts Python Developer // ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What the difference between the two RE?
daedae11 wrote: import re re.match(^hello, hello) re.match(hello, hello) Please give a string that matches RE ^hello but does not match RE hello, or matches RE hello but does not match RE ^hello. re.match always matches the beginning of the string, so re.match(^hello, something) re.match(hello, something) are identical. re.search will search anywhere in the string, not just the beginning, so: re.search(^hello, something) means find the beginning of the string followed by h e l l o while re.search(hello, something) means find h e l l o anywhere in the string. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What the difference between the two RE?
On Thu, Feb 9, 2012 at 1:15 AM, daedae11 daeda...@126.com wrote: import re re.match(^hello, hello) re.match(hello, hello) Please give a string that matches RE ^hello but does not match RE hello, or matches RE hello but does not match RE ^hello. In addition to the other answers, it's important to note that nothing in these REs require it to be a word. So both of the above will match the hello in hellonwheels for example. -- Brett Ritter / SwiftOne swift...@swiftone.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] What the difference between the two RE?
import re re.match(^hello, hello) re.match(hello, hello) Please give a string that matches RE ^hello but does not match RE hello, or matches RE hello but does not match RE ^hello. daedae11___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What the difference between the two RE?
On 2012/02/09 08:15 AM, daedae11 wrote: import re re.match(^hello, hello) re.match(hello, hello) Please give a string that matches RE ^hello but does not match RE hello, or matches RE hello but does not match RE ^hello. daedae11 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The caret ^ means At the beginning of the line so 'And they said hello' will not be matched by the regex pattern '^hello'. The docs are pretty good on the module http://docs.python.org/library/re.html http://docs.python.org/howto/regex.html -- Christian Witts Python Developer // ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What the difference between the two RE?
On 2012-02-09 08.16, Christian Witts wrote: On 2012/02/09 08:15 AM, daedae11 wrote: import re re.match(^hello, hello) re.match(hello, hello) Please give a string that matches RE ^hello but does not match RE hello, or matches RE hello but does not match RE ^hello. daedae11 ___ Tutor maillist -Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor The caret ^ means At the beginning of the line so 'And they said hello' will not be matched by the regex pattern '^hello'. The docs are pretty good on the module http://docs.python.org/library/re.html http://docs.python.org/howto/regex.html -- Christian Witts Python Developer This is also a good source of information for regexp patterns in general: http://www.regular-expressions.info/ Göran Törnquist Usertime ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor