正则表达式语法错误代码:800A1399 [英] Regular expression syntax error code: 800A1399

查看:39
本文介绍了正则表达式语法错误代码:800A1399的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习正则表达式和 vbscript,以便通过每月添加用户输入的文本将文本附加到 .c 文件的新行.我在线收到一个正则表达式语法错误:68 char: 1 of the following VBScript,需要帮助整理:

I am learning regex and vbscript in order to append text to a .c file on a new line by adding user inputted text on a monthly basis. I receive a regular expression syntax error on line: 68 char: 1 of the following VBScript, and need help sorting it out:

path = "<C:\Users\Parth\Desktop\C06S3000.C>"
Set re = New RegExp 

inputstr1 = InputBox("enter short name for recovery month, example: dec2015")
re.Pattern = "^([a-zA-Z]{3,5}\d{4})$"
re.IgnoreCase = True
Do While re.Test(inputstr1) <> True
  inputstr1 = InputBox("incorrect entry; enter short name for recovery month, example: dec2015")
Loop

inputstr2 = InputBox("enter full name for recovery month, example: december_2015")
re.Pattern = "^([a-zA-Z_]{3,10}\d{4})$"
re.IgnoreCase = True
Do While re.Test(inputstr2) <> True
  inputstr2 = InputBox("incorrect entry; enter full name for recovery month, example: december_2015")
Loop

inputstr3 = InputBox("enter names of all affected groups for recovery month separated by commas and single space, example: a1, a2, a3,...")
re.Pattern = "^(([a-zA-Z_]{1,2}\d{1,2}[,]\s)*)$"
re.IgnoreCase = True
Do While re.Test(inputstr3) <> True
  inputstr3 = InputBox("incorrect entry, enter names of all affected groups for recovery month separated by commas and space, example: a1, a2, a3,... ")
Loop
grpString1 = split(inputstr3, ",")

inputstr4 = InputBox("enter loss percentage for each group separated by commas and a space; example: 0.00283148378304, 0.39331380134641, ...")
re.Pattern = "^((\d\.\d{14}[,]\s)*)$"
Do While re.Test(inputstr4) <> True
  inputstr4 = InputBox("incorrect entry, enter loss percentage for each group separated by commas and a space; example: 0.00283148378304, 0.39331380134641, ... ")
Loop  
grpString2 = split(inputstr4, ",")

If UBound(grpString1) = UBound(grpString2) Then
Else
  'use more efficient code by implementing class variables with a function, for example, in future versions'
  'source: https://bytes.com/topic/asp-classic/answers/125942-vbscript-function-returning-multiple-values'

  response.write("affected group count does not match loss percentage count; reenter these values to match count")
  inputstr3 = InputBox("enter names of all affected groups for recovery month separated by commas and single space, example: a1, a2, a3,...")
  re.Pattern = "^(([a-zA-Z_]{1,2}\d{1,2}[,]\s)*)$"
  re.IgnoreCase = True
  Do While re.Test(inputstr3) <> True
    inputstr3 = InputBox("incorrect entry, enter names of all affected groups for recovery month separated by commas and space, example: a1, a2, a3,... ")
  Loop
  grpString1 = Split(inputstr3, ",")

  inputstr4 = InputBox("enter loss percentage for each group separated by commas and a space; example: 0.00283148378304, 0.39331380134641, ...")
  re.Pattern = "^((\d\.\d{14}[,]\s)*)$"
  Do While re.Test(inputstr4) <> True
    inputstr4 = InputBox("incorrect entry, enter loss percentage for each group separated by commas and a space; example: 0.00283148378304, 0.39331380134641, ... ")
  Loop  
  grpString2 = Split(inputstr4, ",")
End If

Set objfso = CreateObject("Scripting.FileSystemObject")
If objfso.FileExists(path) Then
  Set objFile = objFSO.OpenTextFile(path).ReadAll
End If

'source: http://www.tutorialspoint.com/vbscript/vbscript_split_function.htm'
ublptm = UBound(grpString1)
For i=0 To ublptm 'where lptm = loss_pct_avg_monthyear[group] = percent;'
  lptmStr = lptmstr + "loss_pct_through_[" & grpString1(i) & "] = " & grpString2(i) & ";" & vbCrLf  
Next

re.Pattern = "(?<=loss_pct_through_([a-zA-Z]{3,5}\d{4})\[([a-zA-Z_]{1,2}\d{1,2})\]\s=\s\d\.\d{14}[;]\n)\n(?=\}\n)"

'source: http://stackoverflow.com/questions/13588622/using-vbscript-to-find-and-replace-all-multi-line-text-between-curly-braces-of-a'

objFile = re.Replace(objFile, vbCrLf & lptmstr & vbCrLf)

第 68 行在哪里:

objFile = re.Replace(objFile, vbCrLf & lptmstr & vbCrLf)

正则表达式模式应该寻找 .c 代码并将用户输入附加到以换行符开头的换行符上,如下所示:

The regex pattern is supposed to seek .c code and append user inputs on a newline starting with a newline character as follows:

原始文件:

 loss_pct_through_nov2015[a4] = 0.13155605112872;
 loss_pct_through_nov2015[a5] = 0.23415898757080;

 loss_pct_through_dec2015[a2] = 0.00283148378304;
 loss_pct_through_dec2015[a3] = 0.39331380134641;
 loss_pct_through_dec2015[a4] = 0.56333929692615;
 loss_pct_through_dec2015[a5] = 0.04051541794440; <-append content from here
\n
}

更新文件:

 loss_pct_through_nov2015[a4] = 0.13155605112872;
 loss_pct_through_nov2015[a5] = 0.23415898757080;

 loss_pct_through_dec2015[a2] = 0.00283148378304;
 loss_pct_through_dec2015[a3] = 0.39331380134641;
 loss_pct_through_dec2015[a4] = 0.56333929692615;
 loss_pct_through_dec2015[a5] = 0.04051541794440;   
\n <--new newline character replacing the old one to append content below
 loss_pct_through_jan2016[a2] = 0.04051541794440;
 loss_pct_through_jan2016[a4] = 0.04051541794440;

}

推荐答案

您有一个 积极的后视断言 ((?<=...)) 在这个表达式的开头:

You have a positive lookbehind assertion ((?<=...)) at the beginning of this expression:

re.Pattern = "(?<=loss_pct_through_([a-zA-Z]{3,5}\d{4})\[([a-zA-Z_]{1,2}\d{1,2})\]\s=\s\d\.\d{14}[;]\n)\n(?=\}\n)"

VBScript 正则表达式引擎不支持这些.

The VBScript regular expression engine doesn't support these.

这篇关于正则表达式语法错误代码:800A1399的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆