Editing Regex Code -


i hoping can me think regex problem.

i have program takes piece of html code , extracts phone numbers , separates them semi colons. change extracts between 2 specific text strings backslashes in between. example

stringone/******/stringtwo stringone/876876876876876/stringtwo stringone/abcdefghijklmnopqrstuvwxyz/stringtwo 

before , after total string there may or may not spaces, letters, numbers or special characters.

i have tried regex can't figured out. assume (and instinct) line needs changing one:

    .pattern = "(\+([\d \(\)-]+){10,15})|((\d( |-))?\(?\d{2,4}\)?( |-)\d{3,4}( |-)\d{3,4})|(\d{3,4}( |-)\d{7})" 

but entire code follows:

function main ( strtext )      dim strresult      strresult = extract_phone_numbers ( strtext )      main = strresult  end function  ' function extracts phone numbers specific string using pattern matching (a regular expression).  function extract_phone_numbers ( strtext )      dim strresult      set regularexpressionobject = new regexp      regularexpressionobject     .pattern = "(\+([\d \(\)-]+){10,15})|((\d( |-))?\(?\d{2,4}\)?( |-)\d{3,4}( |-)\d{3,4})|(\d{3,4}( |-)\d{7})"     .ignorecase = true     .global = true     end      set objmatches = regularexpressionobject.execute( strtext )      each objmatch in objmatches         if ( instr ( strresult, objmatch.value ) = 0  )              if ( len ( strresult ) > 0  )                  strresult = strresult + "; "             end if                   strresult = strresult + objmatch.value         end if           next      set regularexpressionobject = nothing      strresult = trim ( strresult )      extract_phone_numbers = strresult  end function 

can me changed?

  1. in general, pattern matching pattern stringone/[^/]*/stringtwo, including slashes
  2. to match inside, not including slashes, there several ways. if flavor supports lookarounds, go this: (?<=stringone/)[^/]*(?=/stringtwo)
  3. vbs doesn't support lookbehind, need match whole string, capturing wanted part group 1: stringone/([^/]*)/stringtwo

on the demo, @ group 1 captures in right pane. note in regex tester slashes had escaped.

explanation

stringone/ matches literal stringone/, negated character class [^/] matches 1 character not /, , * quantifier repeats 0 or more times, match final /stringtwo.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -