regex - Problems with basic python syntax for regular expressions -


i'm studying bio-informatics exam there things professor did don't understand. i've tried looking can please explain in non-programmer language? have tried looking things understand i'm bit clueless.my questions this;

import re line = "cats smarter dogs" matchobj = re.match(r'(.*) (.*?)*',line,re.m|re.i)  if matchobj:   print("matchobj.group():",matchobj.group())   print("matchobj.group():",matchobj.group(1))   print("matchobj.group():",matchobj.group(2)) 

my questions:

  • what (.*) do, i'm guessing you're trying match 'cats' why don't type cats? understand . means 'any character' don't understand * does

  • what combination (.?)' do?

  • what re.m|re.i do?

thanks mutch! i'm starting become bit desperate. mind doesn't work in right way understand kind of things think.

i'll give first one, these are easy regex ever see out there in wild :)

. character

* unlimited times

so... (.*) character unlimited times

here link python docs on regular expressions https://docs.python.org/2/library/re.html... can each character. try 1 , post here questions if stuck :)


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -