exp with stack

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
michalmas
Forum Newbie
Posts: 14
Joined: Wed Apr 29, 2009 9:04 am

exp with stack

Post by michalmas »

Hello,

Can anyone help me with the following problem:

I have text:

Code: Select all

   some text is here ble bla blu
    now there is some structure
    [b]struc [/b]something
    now we are inside and next element:
    [b]elem [/b]value
    something els, and again
    [b]elem [/b]val2
    [b]end struc[/b]
    this is not inside
    elem valXXX
and i want to extract all elem elements that are inside some other struc element.

So, the output of the example above is:

elem value
elem val2


but not
elem valXXX.


Any solution (or attempt) close to the result will make me happy.


Thanks!
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: exp with stack

Post by prometheuzz »

---
Last edited by prometheuzz on Sat May 09, 2009 1:55 am, edited 1 time in total.
michalmas
Forum Newbie
Posts: 14
Joined: Wed Apr 29, 2009 9:04 am

Re: exp with stack

Post by michalmas »

does it match also to many struck-end struck occurances?:

Code: Select all

    
     some text is here ble bla blu
     now there is some structure
     struc something
     now we are inside and next element:
     elem value
     something els, and again
     elem val2
     end struc
     this is not inside
     elem valXXX
     struck 2
     elem val3
     xxxx
     end struck
 
and is it possible to limit to one expression what you wrote and the additional condition:
that element after the elem node contains val?

thx
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: exp with stack

Post by prometheuzz »

michalmas wrote:does it match also to many struck-end struck occurances?:

Code: Select all

    
     some text is here ble bla blu
     now there is some structure
     struc something
     now we are inside and next element:
     elem value
     something els, and again
     elem val2
     end struc
     this is not inside
     elem valXXX
     struck 2
     elem val3
     xxxx
     end struck
 
and is it possible to limit to one expression what you wrote and the additional condition:
that element after the elem node contains val?

thx
Why don't you give it a try...
michalmas
Forum Newbie
Posts: 14
Joined: Wed Apr 29, 2009 9:04 am

Re: exp with stack

Post by michalmas »

I don't have access to php parser now...

btw: what about the second part of the question:

and is it possible to limit to one expression what you wrote and the additional condition:
that element after the 'elem' node contains 'val' inside?

thx
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: exp with stack

Post by prometheuzz »

michalmas wrote:I don't have access to php parser now...

...
Then I'll wait until you get access to PHP and have tried a couple of things yourself.

Good luck.
michalmas
Forum Newbie
Posts: 14
Joined: Wed Apr 29, 2009 9:04 am

Re: exp with stack

Post by michalmas »

I have problem with enriching the expression. I'd like to make it much more complex:

Code: Select all

 
     some text is here ble bla blu
     some text is here ble bla blu
     START
     some text is here ble bla blu
     * here i ignore the text
     now there is some structure
     struc something
     now we are inside and next element:
     elem value
     something els, and again
     elem val2
     * elem ignored
     end struc
     this is not inside
    * struc sth
    * but it was ignored
     elem valXXX
    *end struc
 
I take only the thing that appear after the START element. So, if there is struc before, it must be ignored.
Next to it, all lines that start with * should be ignored.

The expected output is the same as last time.

I tried with ^ and $, but couldn't make it working with lookaheads. Can you show the solution in one reg exp? If not, can you split it to two but still only using reg exp (without any pre- or post-processing of the text).

@prometheuzz
Yes, i created some more posts on different forums. I did it because i am interested in any possible solution to the problem. Maybe someone could present something more complex but without lookahead (or only with the positive/negative). The problem here is quite serious - it is on the border of the reg exp possibilities. However, it is still possible to create the finite-states automaton for the problem, so the solution in reg exp must exist.
Then I'll wait until you get access to PHP and have tried a couple of things yourself.

Good luck.
I had problems with php server on my PC with Windows and i didn't have the possibility to connect to any server with php at that certain time.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: exp with stack

Post by prometheuzz »

@michalmas, perhaps someone else is willing to give you a hand, but I've lost interest.
I simply don't like it when people post their problems all over different forums without mentioning they do so: in my opinion, that's just wasting other people's time and it doesn't show much appreciation.
michalmas
Forum Newbie
Posts: 14
Joined: Wed Apr 29, 2009 9:04 am

Re: exp with stack

Post by michalmas »

@prometheuzz:
I regret it, but i understand your point.

However, note that it is not always welcome to share links to other forums.

Thanks,
Michal
michalmas
Forum Newbie
Posts: 14
Joined: Wed Apr 29, 2009 9:04 am

Re: exp with stack

Post by michalmas »

Anyone?

Or, if someone tried but has not succeeded, it will be also useful information.

Thanks,
M.
Post Reply