Regular Expressions question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

let say that my string is :
/// <author> aaa
/// <author> bbb
/// <author> ccc

1. how do i match all the authors except author aaa ?

2. how do i append the string "2006" to the authors names found in #1 ?

Thanks.
 
yaron said:
Hi all,

let say that my string is :
/// <author> aaa
/// <author> bbb
/// <author> ccc

1. how do i match all the authors except author aaa ?

(? said:
2. how do i append the string "2006" to the authors names found in #1 ?

Use the Replace method on the above regex and replace with: ${line} 2006

... there are probably smarter expressions than this..!

hth,
Max
 
Markus said:
Use the Replace method on the above regex and replace with: ${line} 2006

.... a bit easier:

///\s<author>\s(?!aaa)(?<author>.*)

and replace with:

$& 2006

Max
 
yaron said:
let say that my string is :
/// <author> aaa
/// <author> bbb
/// <author> ccc

1. how do i match all the authors except author aaa ?

Regex regex = new Regex(@"(?:///\s<author>\s)([^aaa].+)",
(RegexOptions) 0);

2. how do i append the string "2006" to the authors names found in #1 ?

Use Replace with "$1 2006" as the replacement string.
 
Hi Markus,

thanks, it's work in the Expresso tool but not in the VS2003 IDE find
(Ctrl^F) using regular expression, do you know how to use it in the IDE or
maybe the VS2003 IDE doesn't support this regular expression ?

Thanks.
 
Ken said:
yaron said:
let say that my string is :
/// <author> aaa
/// <author> bbb
/// <author> ccc

1. how do i match all the authors except author aaa ?


Regex regex = new Regex(@"(?:///\s<author>\s)([^aaa].+)",
(RegexOptions) 0);

The [^aaa] isn't right.. it means "match any <author> that isn't
followed by *one* 'a'" (instead of three a's). So for example abb will
not match either.

Max
 
yaron said:
Hi Markus,

thanks, it's work in the Expresso tool but not in the VS2003 IDE find
(Ctrl^F) using regular expression, do you know how to use it in the IDE or
maybe the VS2003 IDE doesn't support this regular expression ?

I thought you wanted to do this with code (using the Regex class).. :)

What they have in the CTRL-F dialog doesn't look like the regular
expressions I'm used to.. but this should work:

search for:

{/// \<author\> ~(aaa).*}

replace with:

\1 2006

hth,
Max
 
Markus said:
Regex regex = new Regex(@"(?:///\s<author>\s)([^aaa].+)",
(RegexOptions) 0);

The [^aaa] isn't right.. it means "match any <author> that isn't
followed by *one* 'a'" (instead of three a's). So for example abb will
not match either.

Yep...needed to use the negative look-ahead:

Regex regex = new Regex(@"(?:///\s<author>\s)((?!aaa).+)", (RegexOptions) 0);
 
Thanks to all for your help.


Markus Stoeger said:
I thought you wanted to do this with code (using the Regex class).. :)

What they have in the CTRL-F dialog doesn't look like the regular
expressions I'm used to.. but this should work:

search for:

{/// \<author\> ~(aaa).*}

replace with:

\1 2006

hth,
Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top