.net - Remove duplicate characters using a regular expression -


i need match second , subsequent occurances of * character using regular expression. i'm using replace method remove them here's examples of before , after:

test*     ->  test* (no change) *test*    ->  *test test** *e ->  test* e 

is possible regular expression? thanks

if .net can cope arbitrary amount of behind, try replacing following pattern empty string:

(?<=\*.*)\* 

.

ps home:\> 'test*','*test*','test** *e' -replace '(?<=\*.*)\*','' test* *test test* e 

another way pattern:

(?<=\*.{0,100})\* 

where number 100 can replaced size of target string.

and testing following mono 2.0:

using system; using system.text.regularexpressions;  public class test {     public static void main()     {         regex r = new regex(@"(?<=\*.*)\*");         console.writeline("{0}", r.replace("test*", ""));             console.writeline("{0}", r.replace("*test*", ""));             console.writeline("{0}", r.replace("test** *e", ""));                               } } 

also produced:

test* *test test* e 

Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -