Reputation: 269
I am trying to select everything after CORP ACT OPTION NO
up until 2 new lines and carriage returns (up to safekeeping account in example)
My reg expression atm to extract the info (all of it after CORP ACT OPTION) is
CORP ACT OPTION NO\.([\s\S]*)
Sample dara:
CORP ACT REFERENCE : 007XS0212069115
SENDER'S REFERENCE : 1212070800330001
FUNCTION OF MESSAGE : NEW MESSAGE
CORP ACT EVENT : INTEREST PAYMENT
PLACE OF SAFEKEEPING : US
ISIN : XS0212069115
ISIN/DESCRIPTION : KFW 4.750 071212 GBP
METHOD OF INTEREST COMPUTATION : A006
EX-DATE : 20121207
RECORD DATE : 20121206
CORP ACT OPTION NO. : 001
CORPORATE ACTION OPTION CODE : CASH
CURRENCY OPTION : GBP
RESULTING AMT : GBP617,5
PAYMENT DATE : 20121207
EXCHANGE RATE : GBP/GBP/1,
INTEREST RATE : 4,75
SAFEKEEPING ACCOUNT : 000000000000
CONFIRMED BALANCE : FAMT/13000,
CREDIT/DEBIT IND : CREDIT
How can I select up until the line break above SAFEKEEPING ACCOUNT?
Many thanks.
Upvotes: 12
Views: 52435
Reputation: 6086
The new line based on your file format, encoding, OS,... could be '\r','\r\n' or '\n'. So you need to match two of any of those, i.e [\n|\r\n|\r]{2}
'CORP ACT OPTION NO.([\s\S]*)[\n|\r\n|\r]{2}'
Upvotes: 1
Reputation: 48837
I guess (CORP ACT OPTION NO.*?)(?:\r|\n|\r\n){2}
is what you're looking for. Check this demo to see it working. Don't forget the DOTALL
flag.
Upvotes: 1
Reputation: 39540
/.*\s*:\s*.*/g
should work fine. Without m
the match isn't going to match more than one line.
Explanation of regex:
.*
match as much as possible until followed by:\s*:
*any amount of spaces (0 or more) followed by a litteral :
character\s*
any amount of spaces (0 or more).*
match as much as possible until the linebreakYou can also use capture groups and check every key with every value:
/(.*)\s*:\s*(.*)/g
Upvotes: 8