BE_RegularExpression

BE_RegularExpression ( text ; expression {; options ; replaceString } )

A perl compatible regular expression testing function.

Version : 3.2
Version : 4.0.5 added an extra option "v" to allow you to treat the input as a value list and perform the expression over all the values in the list.

Parameters :
text : the text to be examined.
expression: a "perl compatible" expression - see examples.

options

  • i - case insensitive
  • m - multiline
  • s - dot matches all characters, including newline
  • x - ignore whitespace
  • g - replace all
  • v - treat the input as a value list and iterate over each value

replaceString: if not empty, then a replace is performed rather than a find.

Examples :

BE_RegularExpression ( "abc 123 def" ; "[0-9]+" ) = 123<br>BE_RegularExpression ( $list; "(?:\\S(?![ ]))+$"; "igm" )

To get a list of all the files that end in ".fmp12" for example, you can do :

BE_ValuesUnique ( BE_RegularExpression ( BE_FileListFolder ( $path ) ; "^.*fmp12$" ; "v" ) )

The above example uses BE_ValuesUnique because the default leaves empty lines where the criteria doesn't match, so you'd have as many "values" as there were originally files, but anything not matching the criteria would be empty lines in the list.

Notes about g

This function only has a search for a single match, and the g option only works on replace.  So there's no equivalent of this for a search only, except the v option, which isn't the same thing.  You can simulate g for search with a While function that assumes some starting value of $string and $match.  When doing this, you don't need the v option, as it continues on the next character.

While ( [ out = "" ; find = "" ; string = $string ] ; Length ( string ) > 0  ; 

[ 
find = BE_RegularExpression ( string ; $match ; "m" ) ; 
out = List ( find ; out ) ; 
remValues = RightValues ( string ; ValueCount ( string ) - 1 ) ; 
remString = Right ( string ; Length ( string ) - Position ( string ; find ; 1 ; 1 ) ) ; 
string = Case ( IsEmpty ( find ) ; remValues ; remString ) 

] ; out )<br>

More examples can be found here : http://perldoc.perl.org/perlre.html#Regular-Expressions

Still need help? Contact Us Contact Us