Jump to content

Recommended Posts

Posted

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

Posted

(?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

Posted

(?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

Posted (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.

Lou

I 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 by Paulie
Posted (edited)

*Cough* Josh muttley

And yeah, that was what I meant to say :) And that is also why it is habit

Edited by JFee

Regards,Josh

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...