Skip to Content
avatar image
Former Member

Match textpattern to match two words in a string

I am trying to set a textpattern to match two parts found in a string

The string:

First Part is before Second Part. Wonderful!

Every string which contains 'First Part' and 'Second Part' should match.

Using a reqular expression I'd go with: ^(?=.*\bFirst Part\b)(?=.*\bSecond Part).*$

But that expression as a textpattern does not match.

How to accomplish this using the Powerscript Match function?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 17, 2013 at 12:41 PM

    If you want to test that your string contains First Part then Second Part, you can use the match function like this :

    Match(ls_Test, "First Part.*Second Part")

    But maybe you want something more ?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Chris,

      You're right, i'll be more complete :

      1) If you want the test to be case insensitive you have to lowercase both tested string and text pattern :

      Match(Lower(ls_Test), "first part.*second part")

      2) Be aware that if your "First Part" or "Second Part" strings contain special characters like +*?[]\.^$, then you have to put a backslash before those characters.

      Guillaume

  • avatar image
    Former Member
    Jul 17, 2013 at 09:17 AM

    Hi,

    searching for 'regular expressions and powerbuilder' give multiple results...

    Maybe these could help you :

    http://geni.embeddingperl.com/index.php?post/2011/06/05/Powerbuilder-and-regular-expression

    http://sebastien.kirche.free.fr/powerbuilder/en.html

    Regards,

    Philippe.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 17, 2013 at 12:04 PM

    This works (verified by testing):

    match(test_text, "First Part.*Second Part")

    The ".*" in the middle will match one or more characters until it gets to end of string (no match) or it finds "Second Part" (match).

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 17, 2013 at 11:32 AM

    Hi;

    This works for me in a DW colour expression for a column that has those two words ...

    IF ( match ( lower ( text_test ), 'first part' ) and match ( lower ( text_test ), 'second part' ), rgb (255,0,0), rgb(255,255,255))

    HTH

    Regards ... Chris

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 17, 2013 at 01:26 PM

    Try this

    hth,

    Mark


    match.JPG (14.4 kB)
    Add comment
    10|10000 characters needed characters exceeded