0

$string() = "This is with admin charges";

What I intend to do is to write down an X-Path with RegEx to return the statement above true in the sense that when $string contains "admin charge", then the statement returns true.

See, the statement above can have the following keywords,

  1. admin && charge || charges
  2. administrative && charge || charges
  3. administration && charge || charges

See, all and all, the root keyword here is "admin" and "charge".

Therefore, I would like to write a script that incorporates X-Path and RegEx in it.

The following is my approach so far,

contains(upper-case(normalize-space($string)), "ADMIN CHARGES")

This is still only matches exactly.

I researched, but mostly is to check for single keyword, like

contains(upper-case($string), "^[m/ADMIN CHARGE/]"

Thanks in advance

pemistahl
  • 9,304
  • 8
  • 45
  • 75
Vincent
  • 209
  • 2
  • 9

2 Answers2

2

Regular expression functions are part of the XPATH 2.0 syntax.

However, PHP uses the libxml PHP extension to handle its XML Manipulation, which implements the XPATH 1.0 spec only.

This answer shows an alternative using the PHP/Java Bridge and Saxon. It's probably the best option for the moment.

Using a XSLT 2.0 library, one could use the matches function. From TFM:

fn:matches($input as xs:string?, $pattern as xs:string) as xs:boolean
fn:matches( $input   as xs:string?,
            $pattern     as xs:string,
            $flags   as xs:string) as xs:boolean



matches(., "admin\S*\scharges?", "i")
Community
  • 1
  • 1
Yann Milin
  • 1,335
  • 1
  • 11
  • 22
1

Turning @JWiley's comment into an answer:

contains($string,'admin') and contains($string,'charge')
Phrogz
  • 296,393
  • 112
  • 651
  • 745
  • At the moment it's applied as what JWiley suggested and @Phrogz answered. But I was hoping if the answer given, can be applied where XPath and RegEx be used. Even better, if RegEx be used in this case. – Vincent Jan 14 '13 at 05:44