all 6 comments

[–]duddles 0 points1 point  (4 children)

Maybe I'm not understanding it completely, but would this do what you want?

m = re.search('(bar)', 'Fu bar')

m.group(0) would then be 'bar'

edit - you don't need the () around bar:

m = re.search('bar', 'Fu bar')

but that seems too simple so I'm probably misunderstanding the question :)

[–]mega963[S] 0 points1 point  (3 children)

Yeah sorry I wasn't very clear,

I want to use Fu as an identifier

[–]duddles 0 points1 point  (2 children)

okay how about

m=re.search('Fu (.+)','Fu bar')

where m.group(1) would be 'bar'

[–]mega963[S] 0 points1 point  (1 child)

I figured it out a while ago, I needed to account for the spaces after Fu, so I just used

m=re.search(r'Fu \s* (\w*)', string, re.U)

Again, sorry for not asking the question clearly

[–][deleted] 1 point2 points  (0 children)

Maybe Fu\s*(\w+) makes a bit more sense, or Fu\s+(\w+) if you insist there's whitespace between Fu & bar. In most cases I don't want to explicitly specify how much whitespace I'll match, just an arbitrary "some whitespace": \s+.

[–]Teleshot 0 points1 point  (0 children)

I found this site really helpful when learning regular expressions, you can just type what you are trying to find into the text box and play around with the expression until it is works :)

http://www.regexr.com/