Jump to content

StringRegExp - get data from more lines


Zedna
 Share

Recommended Posts

In Helpfile is:

(?s) . matches anything including newline. (by default "." don't match newline)

This is original patern for one line data:

$data = StringRegExp($text, '<reldp(.*?)</reldp>', 3)oÝ÷ Ù8^±æ«zl§¢Ü(®H§«mzjm²éj׫ú+émX§zX§yÖ­i«­¢+ØÀÌØíÑôMÑÉ¥¹IáÀ ÀÌØíÑáаÌäì±ÐíɱÀ  ý̤¤±Ðì½É±ÀÐìÌäì°Ì¤(ÀÌØíÑôMÑÉ¥¹IáÀ ÀÌØíÑáаÌäì±ÐíɱÀ  ý̤¨ü¤±Ðì½É±ÀÐìÌäì°Ì

@rrror is 1 or 2 for my attempts

Please can somebody help me - I'm regexp noob :)

I need to get data between "<reldp" and "</reldp>" but there are also @CR@LF chars.

This is example of data (1 record on more lines):

<reldp yer="2006" typ="02" dre="">

<client bno="770xxxxxxx">

<name sur="Žaxxx" fir="Radxxxx" tit="" />

<adr cit="Pohxxxxxxx" str="Rabxxxxx" num="823" pos="Poxxx" pnu="69xxx" />

<birth dat="1977-xx-xx" nam="Žaxxx" cit="Brxx" />

</client>

<items coun="1" sdex="" sinc="700" sdar="">

<t1 row="1" cod="3++" fro="2006-02-22" to="2006-02-28" din="7" m1="" m2="" m3="" m4="" m5="" m6="" m7="" m8="" m9="" m10="" m11="" m12="" m13="" inc="700" dex="" dar="" />

</items>

<comp nam="The xxxxxxxxxxxxxxxxxxxxxxxxxx" id="255xxxxx" vs="720xxxxx" cre="2007-01-29" fro="">

<adr cit="Brxx" str="Holxxxxxx" num="1" pnu="639 00" />

</comp>

</reldp>

Thanks
Link to comment
Share on other sites

Hi,

try this:

#include<Array.au3>
$text = FileRead(FileOpen("c:\Downloads\AutoIt-Skripte\Entwicklung\ForumTests\sammlung.txt", 0))
MsgBox(0, "", $text)

$found = StringRegExp($text, "(?s)<reldp.*</reldp>", 3)

ConsoleWrite(@error & @LF)
If IsArray($found) Then
    _ArrayDisplay($found, "Found")
Else
    MsgBox(16, "Error", "Nichts")
EndIf

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

Thank you VERY MUCH th.meger!!

Your help is appreciated :)

It's working good.

My final pattern is:

$out = StringRegExp($data, "(?s)(?-i)<reldp(.*?)</reldp>", 3)oÝ÷ Øuçb{eÈ­'è­ÇjǬz{"¶+â·'è­Ê+­ç-­ën®y¨­æ«­¬¯j[±©Ýþ«¨µä­®)àëpyéájËaDZjjezÊ+¶Ó+,Þ)Ü"¶¬qªbayÈZ­§-z»ºÚ"µÍÝ[ÔYÑ^
    ÌÍÙ]K    ÌÎNÊÜÊIÌLÉÜ[
ÊIÌLÉÝÉÌLËÜ[    ÌLÉÝÉÌÎNËÊ
It's case sensitive by default I believe.

I've been using this the last few days to test them out:

http://www.cuneytyilmaz.com/prog/jrx/

And this as a reference:

http://perldoc.perl.org/perlre.html#Regular-Expressions

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thank you VERY MUCH th.meger!!

Your help is appreciated :)

It's working good.

My final pattern is:

$out = StringRegExp($data, "(?s)(?-i)<reldp(.*?)</reldp>", 3)

I added:

(?-i) - explicitly force case sensitivity

(.*?) - ? for correct return more array values and ()

HI,

glad I could help. I'm currently learning to deal with regExp. If you got some tasks to do, I'll be happy to figure them out.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

@SmOke_N: Thanks for tips _StringBetween is exactly what I accidentally reinvented :-)

But as you can see on my first attempt sometimes only reference don't help (better is some good example)

HI,

glad I could help. I'm currently learning to deal with regExp. If you got some tasks to do, I'll be happy to figure them out.

So long,

Mega

Probably I will need some more help as I will make some more advanced XML parsing, so stay tuned :)

Thanks a lot.

Edited by Zedna
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...