regex - PHP regular expressions exact data inside brackets -


i have string western australia 223/5 (59.3 ov)

i split string , extract following informations regular expressions

$team = 'western australia' $runs = 223/5 $overs = 59.3 

issue is, format of text varying, may of follwing

  • western australia 223/5 (59.3 ov)
  • australia 223/5 (59.3 ov)
  • kwazulu-natal inland
  • sri lanka v west indies

any (like possible have in single regexp) appreciated..

if (preg_match(     '%^                 # start of string     (?p<team>.*?)       # number of characters, few possible (--> team)     (?:\s+              # try match following group: whitespace plus...      (?p<runs>\d+       # string of form number...               (?:/\d+)? # optionally followed /number      )                  # (--> runs)     )?                  # optionally     (?:\s+              # try match following group: whitespace plus...      \(                 # (      (?p<overs>[\d.]+)  # number (optionally decimal) (--> overs)      \s+ov\)            # followed ov)     )?                  # optionally     \s*                 # optional whitespace @ end     $                   # end of string     %six',      $subject, $regs)) {     $team = $regs['team'];     $runs = $regs['runs'];     $overs = $regs['overs']; } else {     $result = ""; } 

you might need catch error if matches <runs> and/or <overs> not present in string. don't know php. (don't know biology...scnr)


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -