Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

matching blocks

Last post 06-27-2009, 12:13 PM by limiter. 5 replies.
Sort Posts: Previous Next
  •  06-14-2009, 1:15 PM 53901

    matching blocks

    hi, im needing to detect some patterns in a block text but don't know what expression use. This is a simplified version of my problem

    start

         some text that can have ()"'., characters

    end

    this dont must be matched

    start

         another random text that can have ()"'., characters

    end

    as you can see, the pattern begins with "start" word and finish with "end" word, and in this sample i must got the next 2 matchs.

    match 1:

    start

         some text that can have ()"'., characters

    end

    match 2:

    start

         another random text that can have ()"'., characters

    end

     

    It's possible to do with regular expressions? im using java btw. Thanks in advance

  •  06-15-2009, 12:14 AM 53907 in reply to 53901

    Re: matching blocks

    limiter:

     This is a simplified version of my problem

    Please ask your actual problem.  We request in the posting guidelines that you DO NOT simplify your data.  More details are helpful, less details are not.


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  06-15-2009, 7:25 PM 53962 in reply to 53907

    Re: matching blocks

    oh sorry, this is my complete problem. I have the next text with this 3 sections that starts with the "rule" word and ends with the "end" word. And i must build a regular expression able to detect all of them separatly. This is an example, the rule-end sections can be more or less, of course

    complete text:

    package com.domain.test;

    import com.domain.test.OtherExampleCode

    import com.domain.test.SomeExampleCode

    rule "MA30"
    when
        $ma30 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 30ms ),    average( $value ) )
    then
        results.setMa30( 3000 );
    end 


    rule "MA20"
    when
        $ma20 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 20ms ),    average( $value ) )
    then
        results.setMa20( $ma20 );
        Integer other = $ma20 * 33;
        System.out.println("result: " + other);
    end

    rule "MA23"
    when
        $ma23 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 23ms ),    average( $value ) )
    then
        System.out.println("some text");
        results.setMa23( $ma20 );
    end
     

    Expected output:

    group 1:

    rule "MA30"
    when
        $ma30 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 30ms ),    average( $value ) )
    then
        results.setMa30( 3000 );
    end

     

    group 2:

    rule "MA20"
    when
        $ma20 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 20ms ),    average( $value ) )
    then
        results.setMa20( $ma20 );
        Integer other = $ma20 * 33;
        System.out.println("result: " + other);
    end

    group 3:

    rule "MA23"
    when
        $ma23 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 23ms ),    average( $value ) )
    then
        System.out.println("some text");
        results.setMa23( $ma20 );
    end 

     

    Thanks

  •  06-15-2009, 10:01 PM 53965 in reply to 53962

    Re: matching blocks

    Raw Match Pattern:
    ^rule.+?end\s*$

    Java Code Example:

    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    class Module1{
    public static void main(String[] asd){
    String sourcestring = "source string to match with pattern";
    Pattern re = Pattern.compile("^rule.+?end\\s*$",Pattern.MULTILINE | Pattern.DOTALL);
    Matcher m = re.matcher(sourcestring);
    int mIdx = 0;
    while (m.find()){
    for( int groupIdx = 0; groupIdx < m.groupCount()+1; groupIdx++ ){
    System.out.println( "[" + mIdx + "][" + groupIdx + "] = " + m.group(groupIdx));
    }
    mIdx++;
    }
    }
    }


    $matches Array:
    (
    [0] => Array
    (
    [0] => rule "MA30"
    when
    $ma30 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 30ms ), average( $value ) )
    then
    results.setMa30( 3000 );
    end


    [1] => rule "MA20"
    when
    $ma20 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 20ms ), average( $value ) )
    then
    results.setMa20( $ma20 );
    Integer other = $ma20 * 33;
    System.out.println("result: " + other);
    end

    [2] => rule "MA23"
    when
    $ma23 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 23ms ), average( $value ) )
    then
    System.out.println("some text");
    results.setMa23( $ma20 );
    end

    )

    )

    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  06-24-2009, 7:03 PM 54287 in reply to 53965

    Re: matching blocks

    i didn't receive the subscription mail, that's strange... but this solution worked great! thanks for your time! and now, how to detect from this group

    group 2:

    rule "MA20"
    when
        $ma20 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 20ms ),    average( $value ) )
    then
        results.setMa20( $ma20 );
        Integer other = $ma20 * 33;
        System.out.println("result: " + other);
    end

    this output. I was only able to detect the when random_characters_and_finishing_with then group

    output from group 2:

    when
        $ma20 : Double() from accumulate( ClosePrice( $value : open ) over window:time( 20ms ),    average( $value ) )

     

     

     thanks!

  •  06-27-2009, 12:13 PM 54365 in reply to 54287

    Re: matching blocks

    i figured how to do it myself, thanks anyway 

View as RSS news feed in XML