regex - VBScript Regular Expression Insert Line -


i try insert line between 2 specific lines in files vbscript :

# ligne 1 # ligne 2 

=>

# ligne 1 # ligne 1 bis # ligne 2 

my script code :

dim regex set regex = new regexp     regex.pattern = "# ligne 1\r\n# ligne 2"       regex.pattern = patrn        regex.ignorecase = not casse    regex.global = true    regexpreplace=regex.replace(source,"# ligne 1\r\n# ligne 1 bis\r\n# ligne 2") 

the expression has been found replacement text bad. result :

# ligne 1\r\n# ligne 1 bis\r\n# ligne 2 

i tried :

regex.pattern = "^# ligne 1$\r\n^# ligne 2$"    regex.ignorecase = not casse    regex.global = true   regex.multiline = true regexpreplace=regex.replace(source,"^# ligne 1$\r\n^# ligne 1 bis$\r\n^# ligne 2$") 

the result :

^# ligne 1$\r\n^# ligne 1 bis$\r\n^# ligne 2$ 

any idea ? thanks

regexpreplace=regex.replace(source,"# ligne 1" & vbcrlf & " # ligne 1 bis" & vbcrlf &"# ligne 2") 

you replace string found matching regular expression string indicated replacement (with exception of capture groups placeholders). inside vbscript \r\n has not same meaning in regular expression, so, if need include carriage return , line feed need directly concatenate them


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -