PowerBuilder supports regular expressions using the match() and replace() functions, but the regular expression syntax is limited compared to other programming languages and regex engines.

Here are some limitations of regular expressions in PowerBuilder:

  • Limited character classes: PowerBuilder regular expressions support the . wildcard to match any character, and the [] syntax to define a character class. However, character classes in PowerBuilder do not support ranges or shorthand classes like \d or \s.

  • Limited quantifiers: PowerBuilder regular expressions support the * and + quantifiers to match zero or more and one or more occurrences, respectively. The ? quantifier is also supported to match zero or one occurrence. However, other quantifiers like {n,m} or *? are not supported.

  • Limited backreferences: PowerBuilder regular expressions support backreferences to captured groups using the \n syntax, where n is the capture group number. However, only up to nine capture groups are supported.

  • Limited lookaround: PowerBuilder regular expressions do not support lookaround assertions like (?=...) or (?!...) to perform positive or negative lookaheads or lookbehinds.

  • No support for modifiers: PowerBuilder regular expressions do not support modifiers like i to perform case-insensitive matching.

Here's an example of how you can use regular expressions in PowerBuilder:

string ls_input, ls_output int li_pos ls_input = "The quick brown fox jumps over the lazy dog" // Find the first occurrence of a word starting with 'q' li_pos = match(ls_input, "\bq\w*", 1) if li_pos > 0 then // Replace the word with 'QUICK' ls_output = replace(ls_input, "\bq\w*", "QUICK", 1, li_pos) MessageBox("Output", ls_output) else MessageBox("Error", "No match found") end if

In this example, we define a string ls_input and search for the first occurrence of a word starting with the letter 'q' using the regular expression \bq\w*, which matches a word boundary followed by the letter 'q' and zero or more word characters.

If a match is found, we replace the matched word with the string 'QUICK' using the replace() function. The MessageBox() function is used to display the output string in a message box. If no match is found, an error message is displayed.

Have questions or queries?
Get in Touch