Connecting Tech Pros Worldwide Forums | Help | Site Map

filter string over regular expression

Xavier
Guest
 
Posts: n/a
#1: Nov 19 '05
hello,

in a string which i read from a textfile there are some lines, which must be
eliminated.
The content of the stringvariable is for example :

myString="
--comment 1
Update .....
--comment 2 .......
SELECT DISTINCT .....
...."

how can i eliminate all the comment lines marked with --
so that i get

myString="
Update .....
SELECT DISTINCT .....
...."

The new string has no more lines with --

thanks
Xavier











Kevin Spencer
Guest
 
Posts: n/a
#2: Nov 19 '05

re: filter string over regular expression


Hi Xavier,

The following will match any line that begins with "--"

(?m)^--.*\r*\n

You can use Regex.Replace to take them out.
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Xavier" <Xavier@discussions.microsoft.com> wrote in message
news:76E512CE-09E9-4F5A-904D-D19DA83865B1@microsoft.com...[color=blue]
> hello,
>
> in a string which i read from a textfile there are some lines, which must
> be
> eliminated.
> The content of the stringvariable is for example :
>
> myString="
> --comment 1
> Update .....
> --comment 2 .......
> SELECT DISTINCT .....
> ..."
>
> how can i eliminate all the comment lines marked with --
> so that i get
>
> myString="
> Update .....
> SELECT DISTINCT .....
> ..."
>
> The new string has no more lines with --
>
> thanks
> Xavier
>
>
>
>
>
>
>
>
>
>[/color]


Xavier
Guest
 
Posts: n/a
#3: Nov 19 '05

re: filter string over regular expression


i tryed to use the match with the folowing function

vInputString = Regex.Replace(vInputString, "^--.*\r*\n", "")

where the inputstring is the value what i get from the textfile and has the
value
vInputString ="
--comment 1
select * from Table1 where AreaId=1001
--other comment

--comment 2
Select * from table 2
--GO--
"

I want to eliminate all lines what beginns with --
The result must be in my example only
vInputString ="
select * from Table1 where AreaId=1001
Select * from table 2"



but i did not work

any idea?

thanks





"Kevin Spencer" wrote:
[color=blue]
> Hi Xavier,
>
> The following will match any line that begins with "--"
>
> (?m)^--.*\r*\n
>
> You can use Regex.Replace to take them out.
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> ..Net Developer
> Ambiguity has a certain quality to it.
>
> "Xavier" <Xavier@discussions.microsoft.com> wrote in message
> news:76E512CE-09E9-4F5A-904D-D19DA83865B1@microsoft.com...[color=green]
> > hello,
> >
> > in a string which i read from a textfile there are some lines, which must
> > be
> > eliminated.
> > The content of the stringvariable is for example :
> >
> > myString="
> > --comment 1
> > Update .....
> > --comment 2 .......
> > SELECT DISTINCT .....
> > ..."
> >
> > how can i eliminate all the comment lines marked with --
> > so that i get
> >
> > myString="
> > Update .....
> > SELECT DISTINCT .....
> > ..."
> >
> > The new string has no more lines with --
> >
> > thanks
> > Xavier
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >[/color]
>
>
>[/color]
Kevin Spencer
Guest
 
Posts: n/a
#4: Nov 19 '05

re: filter string over regular expression


> but i did not work

Apparently not.
[color=blue]
> any idea?[/color]

Try using the WHOLE Regular Expression I gave you:

(?m)^--.*\r*\n

The following is a link to a FREEWARE Regular Expression Building and
Testing tool that works quite well:

http://www.ultrapico.com/Expresso.htm

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Xavier" <Xavier@discussions.microsoft.com> wrote in message
news:D24B00BB-AD4C-4E70-A7EA-03166A701361@microsoft.com...[color=blue]
>i tryed to use the match with the folowing function
>
> vInputString = Regex.Replace(vInputString, "^--.*\r*\n", "")
>
> where the inputstring is the value what i get from the textfile and has
> the
> value
> vInputString ="
> --comment 1
> select * from Table1 where AreaId=1001
> --other comment
>
> --comment 2
> Select * from table 2
> --GO--
> "
>
> I want to eliminate all lines what beginns with --
> The result must be in my example only
> vInputString ="
> select * from Table1 where AreaId=1001
> Select * from table 2"
>
>
>
> but i did not work
>
> any idea?
>
> thanks
>
>
>
>
>
> "Kevin Spencer" wrote:
>[color=green]
>> Hi Xavier,
>>
>> The following will match any line that begins with "--"
>>
>> (?m)^--.*\r*\n
>>
>> You can use Regex.Replace to take them out.
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> Ambiguity has a certain quality to it.
>>
>> "Xavier" <Xavier@discussions.microsoft.com> wrote in message
>> news:76E512CE-09E9-4F5A-904D-D19DA83865B1@microsoft.com...[color=darkred]
>> > hello,
>> >
>> > in a string which i read from a textfile there are some lines, which
>> > must
>> > be
>> > eliminated.
>> > The content of the stringvariable is for example :
>> >
>> > myString="
>> > --comment 1
>> > Update .....
>> > --comment 2 .......
>> > SELECT DISTINCT .....
>> > ..."
>> >
>> > how can i eliminate all the comment lines marked with --
>> > so that i get
>> >
>> > myString="
>> > Update .....
>> > SELECT DISTINCT .....
>> > ..."
>> >
>> > The new string has no more lines with --
>> >
>> > thanks
>> > Xavier
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >[/color]
>>
>>
>>[/color][/color]


Xavier
Guest
 
Posts: n/a
#5: Nov 19 '05

re: filter string over regular expression


yes, i also noticed this...
Now it's all fine

thanks, for your help
Xavier


"Kevin Spencer" wrote:
[color=blue][color=green]
> > but i did not work[/color]
>
> Apparently not.
>[color=green]
> > any idea?[/color]
>
> Try using the WHOLE Regular Expression I gave you:
>
> (?m)^--.*\r*\n
>
> The following is a link to a FREEWARE Regular Expression Building and
> Testing tool that works quite well:
>
> http://www.ultrapico.com/Expresso.htm
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> ..Net Developer
> Ambiguity has a certain quality to it.
>
> "Xavier" <Xavier@discussions.microsoft.com> wrote in message
> news:D24B00BB-AD4C-4E70-A7EA-03166A701361@microsoft.com...[color=green]
> >i tryed to use the match with the folowing function
> >
> > vInputString = Regex.Replace(vInputString, "^--.*\r*\n", "")
> >
> > where the inputstring is the value what i get from the textfile and has
> > the
> > value
> > vInputString ="
> > --comment 1
> > select * from Table1 where AreaId=1001
> > --other comment
> >
> > --comment 2
> > Select * from table 2
> > --GO--
> > "
> >
> > I want to eliminate all lines what beginns with --
> > The result must be in my example only
> > vInputString ="
> > select * from Table1 where AreaId=1001
> > Select * from table 2"
> >
> >
> >
> > but i did not work
> >
> > any idea?
> >
> > thanks
> >
> >
> >
> >
> >
> > "Kevin Spencer" wrote:
> >[color=darkred]
> >> Hi Xavier,
> >>
> >> The following will match any line that begins with "--"
> >>
> >> (?m)^--.*\r*\n
> >>
> >> You can use Regex.Replace to take them out.
> >> --
> >> HTH,
> >>
> >> Kevin Spencer
> >> Microsoft MVP
> >> ..Net Developer
> >> Ambiguity has a certain quality to it.
> >>
> >> "Xavier" <Xavier@discussions.microsoft.com> wrote in message
> >> news:76E512CE-09E9-4F5A-904D-D19DA83865B1@microsoft.com...
> >> > hello,
> >> >
> >> > in a string which i read from a textfile there are some lines, which
> >> > must
> >> > be
> >> > eliminated.
> >> > The content of the stringvariable is for example :
> >> >
> >> > myString="
> >> > --comment 1
> >> > Update .....
> >> > --comment 2 .......
> >> > SELECT DISTINCT .....
> >> > ..."
> >> >
> >> > how can i eliminate all the comment lines marked with --
> >> > so that i get
> >> >
> >> > myString="
> >> > Update .....
> >> > SELECT DISTINCT .....
> >> > ..."
> >> >
> >> > The new string has no more lines with --
> >> >
> >> > thanks
> >> > Xavier
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >>
> >>
> >>[/color][/color]
>
>
>[/color]
Closed Thread