next up previous contents index
Next: String Substitution Up: perlmatch: Using Perl as Previous: Note:   Contents   Index

Bulk Matching

XSB-perl interface also supports bulk matching through the predicate bulk_match/3. Here, you get all the substrings that match the patters at once, in a list, and then you can process the matches as you wish. However, this does not give you full access to submatches. More precisely, if you use parenthesized expressions, then you get the list of non-null values in the variables $1, $2, etc. If you do not use parenthesized regular expressions, you get the result of the full match. For instance,
  :- bulk_match('First 11.22 ; next: 3.4', 'm/(\d+)\.?(\d*)/g', Lst).
  Lst=[11,22,3,4]
  yes
  :- bulk_match('First 11.22 ; next: 3.4', 'm/\d+\.?\d*/g', Lst).
  Lst=[11.22,3.4]
  yes
bulk_match/3 never fails. If there is no match, it returns an empty list.

Please note that you must specify `g' at the end of the pattern in order to get something useful. This ia Perl thing! If you do not, instead of returning a list of matches, Perl will think that you just want to test if there is a match or not, and it will return [1] or [], depending on the outcome.



Luis Fernando P. de Castro 2003-06-27