467,911 Members | 1,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,911 developers. It's quick & easy.

Need help with RegEx

This code
Regex ge = new Regex("[,\f/]");

string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_");

returns

"8 kBit_s_ 8_000 Hz_ Mono"
and I need
"8_kBit_s_ 8_000_Hz_ Mono"

http://www.alvas.net - Audio tools for C# and VB.Net developers

Nov 23 '07 #1
  • viewed: 1155
Share:
8 Replies
On Nov 23, 10:10 am, "Alexander Vasilevsky" <al...@alvas.netwrote:
This code
Regex ge = new Regex("[,\f/]");

string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_");

returns

"8 kBit_s_ 8_000 Hz_ Mono"
and I need
"8_kBit_s_ 8_000_Hz_ Mono"
Could you explain the rules for that? It's not clear in which
situations you'd want a space to be replaced by _ and in which
situations you wouldn't.

(What is the form feed in the regular expression meant to be doing, by
the way?)

Jon
Nov 23 '07 #2
I want to replace all white space " " to "_". See below

"8 kBit_s_ 8_000 Hz_ Mono"
"8_kBit_s_ 8_000_Hz_ Mono"

http://www.alvas.net - Audio tools for C# and VB.Net developers
"Jon Skeet [C# MVP]" <sk***@pobox.com???????/???????? ? ????????
?????????:
news:5c**********************************@d27g2000 prf.googlegroups.com...
On Nov 23, 10:10 am, "Alexander Vasilevsky" <al...@alvas.netwrote:
>This code
Regex ge = new Regex("[,\f/]");

string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_");

returns

"8 kBit_s_ 8_000 Hz_ Mono"
and I need
"8_kBit_s_ 8_000_Hz_ Mono"

Could you explain the rules for that? It's not clear in which
situations you'd want a space to be replaced by _ and in which
situations you wouldn't.

(What is the form feed in the regular expression meant to be doing, by
the way?)

Jon

Nov 23 '07 #3
The decision proved very easy
Regex ge = new Regex(@"\W");

;)
http://www.alvas.net - Audio tools for C# and VB.Net developers
"Jon Skeet [C# MVP]" <sk***@pobox.com???????/???????? ? ????????
?????????:
news:5c**********************************@d27g2000 prf.googlegroups.com...
On Nov 23, 10:10 am, "Alexander Vasilevsky" <al...@alvas.netwrote:
>This code
Regex ge = new Regex("[,\f/]");

string format = ge.Replace("8 kBit/s, 8,000 Hz, Mono", "_");

returns

"8 kBit_s_ 8_000 Hz_ Mono"
and I need
"8_kBit_s_ 8_000_Hz_ Mono"

Could you explain the rules for that? It's not clear in which
situations you'd want a space to be replaced by _ and in which
situations you wouldn't.

(What is the form feed in the regular expression meant to be doing, by
the way?)

Jon

Nov 23 '07 #4
"Alexander Vasilevsky" <al***@alvas.netschrieb im Newsbeitrag
news:fi***********@behemoth.volia.net...
>I want to replace all white space " " to "_". See below
to match any Whitespace use \s
>
"8 kBit_s_ 8_000 Hz_ Mono"
"8_kBit_s_ 8_000_Hz_ Mono"
there is a space before 8 and before Mono wich is not replaced. I suppose
this is a typo.

Christof

Nov 23 '07 #5
"Alexander Vasilevsky" <al***@alvas.netschrieb im Newsbeitrag
news:fi***********@behemoth.volia.net...
The decision proved very easy
Regex ge = new Regex(@"\W");
this matches all characters, wich are nor letter nor digit. So it will also
replace some non-whitespace charackters. E.g. +*#()&%

Christof

Nov 23 '07 #6
Yes. Well done!

http://www.alvas.net - Audio tools for C# and VB.Net developers
"Christof Nordiek" <cn@nospam.de???????/???????? ? ???????? ?????????:
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Alexander Vasilevsky" <al***@alvas.netschrieb im Newsbeitrag
news:fi***********@behemoth.volia.net...
>The decision proved very easy
Regex ge = new Regex(@"\W");
this matches all characters, wich are nor letter nor digit. So it will
also replace some non-whitespace charackters. E.g. +*#()&%

Christof

Nov 23 '07 #7
On Nov 23, 10:56 am, "Alexander Vasilevsky" <al...@alvas.netwrote:
I want to replace all white space " " to "_". See below

"8 kBit_s_ 8_000 Hz_ Mono"
"8_kBit_s_ 8_000_Hz_ Mono"
That hasn't replaced all spaces with _ - you've still got a space
before the 8 and before the M. Do you *actually* want the result to be

"8_kBit_s_8_000_Hz_Mono"

?

It's really, really important to be absolutely accurate in what you
want, otherwise we won't be able to help you.

Jon
Nov 23 '07 #8
Yes. The decision proved very easy
Regex ge = new Regex(@"\W");

;)

http://www.alvas.net - Audio tools for C# and VB.Net developers
"Jon Skeet [C# MVP]" <sk***@pobox.com???????/???????? ? ????????
?????????:
news:f9**********************************@e6g2000p rf.googlegroups.com...
On Nov 23, 10:56 am, "Alexander Vasilevsky" <al...@alvas.netwrote:
>I want to replace all white space " " to "_". See below

"8 kBit_s_ 8_000 Hz_ Mono"
"8_kBit_s_ 8_000_Hz_ Mono"

That hasn't replaced all spaces with _ - you've still got a space
before the 8 and before the M. Do you *actually* want the result to be

"8_kBit_s_8_000_Hz_Mono"

?

It's really, really important to be absolutely accurate in what you
want, otherwise we won't be able to help you.

Jon

Nov 23 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael R. Pierotti | last post: by
1 post views Thread by hillcountry74 | last post: by
9 posts views Thread by jmchadha | last post: by
7 posts views Thread by Extremest | last post: by
15 posts views Thread by morleyc | last post: by
3 posts views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by
4 posts views Thread by Danny Ni | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.