4

I cant make this code work with the regex *... it appears that * isnt a regex for anything before page.. the txt file.pagdel contains random directory locations for the page and the page number like

H:\teste\pages\page_10

H:\teste\blankpages\page_11

i need to replace all directory structure in the bat file for an specific directory stored in a string variable called replace

example

H:\teste\pages\page_10 -- old pagdel

H:\teste\blankpages\page_11 -- old pagdel

H:\teste\newpages\page_10 -- new pagdel

H:\teste\newpages\page_11 -- new pagdel

File.WriteAllText("H:\\teste\\batch\\pagdel.bat", 
   Regex.Replace(File.ReadAllText("H:\\teste\\batch\\pagdel.bat"), 
   "*page_", replace));

What im doing wrong.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
VictorLS
  • 59
  • 2
  • I believe this stackoverflow question might help answer your question - [regular-expression-wildcard](http://stackoverflow.com/questions/15275718/regular-expression-wildcard) – ProjectNapalm Nov 12 '13 at 18:36

1 Answers1

1

I think what you need is to change regex:

from "*page_" to ".*page_"

Hope it helps. Cheers.

EDIT:

replace = "H:\teste\newpages\page_";
Kamil Wozniak
  • 430
  • 3
  • 7
  • when i use your syntax this error appearsAn unhandled exception of type 'System.ArgumentException' occurred in System.dll Additional information: analysing "*.teste_" - Quantifier {x,y} following nothing – VictorLS Nov 13 '13 at 16:22
  • @VictorLS Please let me know if You are using replace like in the edit part of the answer. – Kamil Wozniak Nov 13 '13 at 16:34
  • @VictorLS I just saw, that You misplaced `.` character. It should be like this: `".*teste_"` Please change that and it should work properly. – Kamil Wozniak Nov 13 '13 at 16:36