50

trying to write an regex that can find all patterns

p = "q=http://.*\.doc" in 

text = "q=http://11111.doc,q=http://22222.doc"

when I did finall on text,

I get the whole thing, i.e. q=http://11111.doc,q=http://22222.doc

but not q=http://11111.doc and q=http://22222.doc

how do I fix it?

1 Answer 1

105

That's because * is a greedy quantifier, trying to match as much as it can. Make it *?:

q=http://.*?\.doc

More information can be found in the Regular Expression HOWTO: Greedy versus Non-greedy

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.