locked
problem about regular express's reverse certainly pre-check... RRS feed

  • Question

  • content = "1<body>2</body>3"

    '.........

    re.Pattern = "(?<=\<\/body>)[\s\S]*"
    content = re.Replace(content, "")

    expect result is

    1<body>2</body>

    , but an error occurred in VB6:

    realtime error '5017'
    method '~' for the object '~' failure

    i got the better way to get contents in body tag, but why the express has this error?

    some guy help me to test this express in RegexBuddy, it's passed, but also stucked in VB6, is this a bug of VB6?

    Wednesday, June 13, 2012 3:16 AM

Answers

  • I am not sure but probably Look-Behind feature is not supported in VBScript Regex.

    • Marked as answer by itakeblue Wednesday, June 13, 2012 10:42 AM
    Wednesday, June 13, 2012 7:58 AM
    Answerer
  • On Wed, 13 Jun 2012 03:16:53 +0000, itakeblue wrote:
     
    >
    >
    >content = "1<body>2</body>3"
    >
    >'.........
    >
    >re.Pattern = "(?<=\<\/body>)[\s\S]*"
    >content = re.Replace(content, "")
    >
    >expect result is
    >
    >1<body>2</body>
    >
    >, but an error occurred in VB6:
    >
    >realtime error '5017'
    >method '~' for the object '~' failure
    >
    >i got the better way to get contents in body tag, but why the express has this error?
    >
    >some guy help me to test this express in RegexBuddy, it's passed, but also stucked in VB6, is this a bug of VB6?
     
    Your regex is malformed according to the rules of the flavor you are using.  Specifically:
     
    (?<=\<\/body>)[\s\S]*
     
    VBScript does not support lookbehind «(?<=\<\/body>)»
       VBScript does not support word boundaries that match specifically at the start or end of a word «\<»
       To match a literal angle bracket, remove the backslash.  Angle brackets are not metacharacters.  Escaping them is pointless. «\<»
       Created with RegexBuddy
     
    Try:
     
    re.Pattern = "(</body>)[\s\S]*"
    content = re.Replace(content, "$1")
     

    Ron
    • Marked as answer by itakeblue Wednesday, June 13, 2012 10:42 AM
    Wednesday, June 13, 2012 10:11 AM

All replies

  • I am not sure but probably Look-Behind feature is not supported in VBScript Regex.

    • Marked as answer by itakeblue Wednesday, June 13, 2012 10:42 AM
    Wednesday, June 13, 2012 7:58 AM
    Answerer
  • On Wed, 13 Jun 2012 03:16:53 +0000, itakeblue wrote:
     
    >
    >
    >content = "1<body>2</body>3"
    >
    >'.........
    >
    >re.Pattern = "(?<=\<\/body>)[\s\S]*"
    >content = re.Replace(content, "")
    >
    >expect result is
    >
    >1<body>2</body>
    >
    >, but an error occurred in VB6:
    >
    >realtime error '5017'
    >method '~' for the object '~' failure
    >
    >i got the better way to get contents in body tag, but why the express has this error?
    >
    >some guy help me to test this express in RegexBuddy, it's passed, but also stucked in VB6, is this a bug of VB6?
     
    Your regex is malformed according to the rules of the flavor you are using.  Specifically:
     
    (?<=\<\/body>)[\s\S]*
     
    VBScript does not support lookbehind «(?<=\<\/body>)»
       VBScript does not support word boundaries that match specifically at the start or end of a word «\<»
       To match a literal angle bracket, remove the backslash.  Angle brackets are not metacharacters.  Escaping them is pointless. «\<»
       Created with RegexBuddy
     
    Try:
     
    re.Pattern = "(</body>)[\s\S]*"
    content = re.Replace(content, "$1")
     

    Ron
    • Marked as answer by itakeblue Wednesday, June 13, 2012 10:42 AM
    Wednesday, June 13, 2012 10:11 AM