Re: RegExp - please help me! (Posting On Python-List Prohibited)

2017-12-26 Thread szykcech
W dniu wtorek, 26 grudnia 2017 21:53:14 UTC+1 użytkownik Lawrence D’Oliveiro 
napisał:
> On Wednesday, December 27, 2017 at 2:15:21 AM UTC+13, szyk...@gmail.com wrote:
> > struct (.+)\s*{\s*(.+)\s*};
> 
> You realize that “.” matches anything? Whereas I think you want to match 
> non-whitespace in those places.

I realize that. I want skip white-spaces from the beginning and from the end 
and match entire body of C++ struct declaration (with white spaces inside as 
well). Maybe should I use "".strip(" ").strip("\t").strip("\n") function after 
matching?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: RegExp - please help me!

2017-12-26 Thread Peter Pearson
On Tue, 26 Dec 2017 05:14:55 -0800 (PST), szykc...@gmail.com wrote:
[snip]
> So: I develop regexp which to my mind should work, but it doesn't and
> I don't know why. The broken regexp is like this: 
> struct (.+)\s*{\s*(.+)\s*};
[snip]

You'll probably get better help faster if you can present your problem
as a couple lines of code, and ask "Why does this print XXX, when I'm
expecting it to print YYY?"  (Sorry I'm not smart enough to give you
an answer to your actual question.)

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: RegExp - please help me!

2017-12-26 Thread Vlastimil Brom
Hi,
I can't comment, whether this is the right approach, as I have no
experiences with C++, but for the matching regular expression itself,
I believe, e.g. the following might work for your sample data (I am
not sure, however, what other details or variants should be taken into
account):

(?s)struct (.+?)\s*\{\s*(.+?)\s*\};

i.e. you need to escape the metacharacters { } with a backslash \
and in the current form of the pattern, you also need the flag DOTALL
- set via (?s) in the example above - in order to also match newlines
with . (alternatively, you could use \n specifically in the pattern,
where needed.) it is possible, that an online regex tester uses some
flags implicitly.

I believe, the non-greedy quantifiers are suitable here  +?
matching as little as possible, otherwise the pattern would match
between the first and the last structs in the source text at once.

It seems, the multiline flag is not needed here, as there are no
affected metacharacters.

hth,
   vbr

=

2017-12-26 14:14 GMT+01:00, szykc...@gmail.com :
> Hi
> I use online Python reg exp editor https://pythex.org/ and I use option
> "multiline".
> I want to use my reg exp in Python script to generate automatically some
> part of my program written in C++ (database structure and serialization
> functions). In order to do this I need: 1) C++ struct name and 2) struct
> definition. Struct definition I need because some inline functions can
> appear bellow my struct definition and makes inappropriate further regexp
> filtering (against variables).
>
> So: I develop regexp which to my mind should work, but it doesn't and I
> don't know why. The broken regexp is like this:
> struct (.+)\s*{\s*(.+)\s*};
> As you can see it has two groups: struct name and struct definition.
> It fails even for such simple structure:
> struct Structure
> {
> int mVariable1;
> QString mVariable2;
> bool mVariable3
> };
>
> Please help me with this regexp or tell me that I neeed do this in other
> way.
>
> thanks, happy Christmas, and happy New Year
> Szyk Cech
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


RegExp - please help me!

2017-12-26 Thread szykcech
Hi
I use online Python reg exp editor https://pythex.org/ and I use option 
"multiline".
I want to use my reg exp in Python script to generate automatically some part 
of my program written in C++ (database structure and serialization functions). 
In order to do this I need: 1) C++ struct name and 2) struct definition. Struct 
definition I need because some inline functions can appear bellow my struct 
definition and makes inappropriate further regexp filtering (against variables).

So: I develop regexp which to my mind should work, but it doesn't and I don't 
know why. The broken regexp is like this:
struct (.+)\s*{\s*(.+)\s*};
As you can see it has two groups: struct name and struct definition.
It fails even for such simple structure:
struct Structure
{
int mVariable1;
QString mVariable2;
bool mVariable3
};

Please help me with this regexp or tell me that I neeed do this in other way.

thanks, happy Christmas, and happy New Year
Szyk Cech
-- 
https://mail.python.org/mailman/listinfo/python-list