perl - RegEx - Indexed/Arrayed Named Capture Groups? -


I have a situation where some form might appear in the format:

  - - AD-H - Header: Data other header: more data message: sdasdasdasd Message: asdasdasdasd Message: asdasdasd  

There may be a lot of messages, or just a couple I step out of Regx I would not want to, because I'm using regx to parse certain header information over messages and send messages with maser They are part of parsing. The text contained in the text can be many.

I would also like to use the named capture group, something like this

  Message: (? & Lt; Message [Mail's index] & gt ;.)  

Where this match matches many times because it can fill in the index. Is anything similar to RegEx? (I will eventually use it in Perl.)

Each group is being separated from the empty line , It can take you closer:

  Use strict; Use warnings; # "Line" separator use two lines as local $ / = "\ n \ n"; Whereas (my $ line = & lt; data & gt;) {my ($ id) = ($ line = ~ / ^ --- id - (\ d +) - $ / m); My @ message = ($ line = ~ / message: (. *) $ / Mg); Print "On line $ id, find these messages:", join (',', @ message), "\ n"; } __DATA__ --- id-1-- header: data one more header: more data message: sdasdasdasd Message: asdasdasdasd Message: asdasdasd --- id-2-- header: data 2 second header: luggage message: more message message: Other message messages: YAM runs: 

 On line 1, found these messages: sdasdasdasd, asdasdasdasd, asdasdasd on line 2, found these messages: more Message, second message, YAM 

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -