[Scilab-users] Regex problem
Samuel Gougeon
sgougeon at free.fr
Fri Aug 19 17:20:26 CEST 2016
Le 19/08/2016 13:26, Gerhard Kreuzer a écrit :
>
> Hi,
>
> I have a data file containing metadata and binary data. I successfully
> scanned the file with .net Regex class, now I want to scan it with
> SciLab, but ….
>
> The relevant part of the file looks like: #data# .. here comes
> binary data … #EOC# .. here comes binary data … #EOC# .. and so on.
>
> My regex in .net notation looks like: #data#((?<data>(?s:.*?))#EOC#)+
> Ok, in SciLab the notation is little different:
> '/#data#((?P<data>(?s:.*?))#EOC#)+/'
> This regex expression didn’t match at all. I start experimenting and
> it looks like that the regex engine stops at a new line character
> (0x0A) which i spart of the binary data block. As far as I know (and
> that isn’t that far) the clause (?s:.*?)means, take any character
> until you find #EOC# but as least as possible.
> No interpretation on 0x0A ….
> Any idea how I can parse my file and get the binary data blocks into
> variables, or at least get pointers to the starting points, so I am
> able to read the binary data with some file read function?
Here is a working example supporting ascii(10). It looks tha "ms"
modifiers must be used together:
--> s = "abcd" + ascii(10) + "efghijkClmnop" + ascii(10) + "fg hiJkl"
s =
abcd
efghijkClmnop
fg hiJkl
--> [trash,trash,captures] = regexp(s, "/c.*?i/*ms*i"); captures
captures =
!cd
efghi !
! !
!Clmnop
fg hi !
So, in your case, you may try with:
regexp(s, "/#data#(.*?)#EOC#)*/ms*");
May be the hardest thing will be to get your binary content as a string.
I don't think that Scilab's regexp() will accept anything else than a
string.
May be there are some Scilab regexp features in reading binary files. To
be investigated.
HTH
Samuel Gougeon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160819/a901f971/attachment.htm>
More information about the users
mailing list