madmatrix Posted July 21, 2008 Share Posted July 21, 2008 Hi All, I'm trying to match part of text in one big string including many lines. For example, my string is: Shipping Address: xxxxxx xxxxxx xxxxxxxxx xxxxxxxxxxx Shipping Date: I tried to get the text between Shipping Address: and Shipping Date:. I use (?:Shipping Address:)\r\n((?s)*)(?:Shipping Method) It can't return the that multiple lines of "x". Also don't know (?m) can be used for some help? Thanks guys. Lou Link to comment Share on other sites More sharing options...
JFee Posted July 21, 2008 Share Posted July 21, 2008 (?s)Shipping Address:\r\n(.*?)\r\nShipping Date: ?s is an option, put it at the beginning of the pattern. Also some unneeded substrings. \1 (first capturing group) returns the text between both, with no CRLFs before or after Regards,Josh Link to comment Share on other sites More sharing options...
madmatrix Posted July 21, 2008 Author Share Posted July 21, 2008 (?s)Shipping Address:\r\n(.*?)\r\nShipping Date: ?s is an option, put it at the beginning of the pattern. Also some unneeded substrings. \1 (first capturing group) returns the text between both, with no CRLFs before or after Thank you very much for your quick response. It works for me. But why you use (.*?) not (.*)? some difference? it works same for me. Lou Link to comment Share on other sites More sharing options...
JFee Posted July 21, 2008 Share Posted July 21, 2008 Habit. There shouldn't be a difference, but I think it looks cleaner. Regards,Josh Link to comment Share on other sites More sharing options...
madmatrix Posted July 21, 2008 Author Share Posted July 21, 2008 Habit. There shouldn't be a difference, but I think it looks cleaner.Thank you John!!! Link to comment Share on other sites More sharing options...
Paulie Posted July 21, 2008 Share Posted July 21, 2008 (edited) Thank you very much for your quick response. It works for me. But why you use (.*?) not (.*)? some difference? it works same for me.LouI think there is a difference between (.*?) and (.*?)(.*?) searches for 1 group of a character string that is unlimited, but it finds the smallest possible match (the "?" inverts the greediness of the "*") (.*)? however searches for 1 group of an unlimited number of characters that may or may not exist (the "?" is now a separate quantifier")I think? Edited July 21, 2008 by Paulie Link to comment Share on other sites More sharing options...
JFee Posted July 21, 2008 Share Posted July 21, 2008 (edited) *Cough* Josh muttley And yeah, that was what I meant to say And that is also why it is habit Edited July 21, 2008 by JFee Regards,Josh Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now