473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

need help on regular expression.


I need to replace the ascII strings in VC++ source code with unicode
compatiable strings. That is I want to replace "abc" with _T("abc") excluding
the strings in #include line or already in _T("..").

I have regular expression

1. {[^_T\(]"([^"\\]*(\\.[^"\\]*)*)"} // get strings without '_T(' prefix
2. {[^include ]"([^"\\]*(\\.[^"\\]*)*)"} //get strings without 'include '
prefix.

how can I get the intersection of these two sets so matched strings can be
replace by '_T(\1)'?

--
Developer
Jul 26 '07 #1
3 2078
* Paul Wu wrote, On 26-7-2007 20:48:
I need to replace the ascII strings in VC++ source code with unicode
compatiable strings. That is I want to replace "abc" with _T("abc") excluding
the strings in #include line or already in _T("..").

I have regular expression

1. {[^_T\(]"([^"\\]*(\\.[^"\\]*)*)"} // get strings without '_T(' prefix
2. {[^include ]"([^"\\]*(\\.[^"\\]*)*)"} //get strings without 'include '
prefix.

how can I get the intersection of these two sets so matched strings can be
replace by '_T(\1)'?

To make sure #include isn't on the line use a negative look behind:

(?<!#include.*)

To make sure you're not already in a _T"..." use a look around as well:

(?<!_T")

All other strings can be replaced (don't match the newline either,
because a string can't span lines in C++ as far as I know):

"[^"\n]*"

Combine:

(?<!#include.*)(?<!_T)"[^\n"]*"

One thing you haven't looked at is an escaped ", you'll probably need to
escape those as well. That's a bit harder as \\\" is an escaped quote,
but \\\\" isn't. There isn't really a regex way for that as far as I
know. You could try:

((^|[^\\])(\\\\)*\\"

Which would lead to:

(?<!#include.*)(?<!_T)"((^|[^\\])(\\\\)*\\"|[^"\n])*"

Which does the trick.

This regex is written using the System.Text.RegularExpressions syntax
and won't work in the Visual Studio find & replace window. You could
probably write a simple commandline tool to do the trick.

Jesse
Jul 26 '07 #2
Thanks a lot. This works well -- there is an VS 2003 addin-on
(http://www.codeproject.com/csharp/SearcherAddIn.asp) that can be used,
alberit it is buggish.
Developer
"Jesse Houwing" wrote:
* Paul Wu wrote, On 26-7-2007 20:48:
I need to replace the ascII strings in VC++ source code with unicode
compatiable strings. That is I want to replace "abc" with _T("abc") excluding
the strings in #include line or already in _T("..").

I have regular expression

1. {[^_T\(]"([^"\\]*(\\.[^"\\]*)*)"} // get strings without '_T(' prefix
2. {[^include ]"([^"\\]*(\\.[^"\\]*)*)"} //get strings without 'include '
prefix.

how can I get the intersection of these two sets so matched strings can be
replace by '_T(\1)'?


To make sure #include isn't on the line use a negative look behind:

(?<!#include.*)

To make sure you're not already in a _T"..." use a look around as well:

(?<!_T")

All other strings can be replaced (don't match the newline either,
because a string can't span lines in C++ as far as I know):

"[^"\n]*"

Combine:

(?<!#include.*)(?<!_T)"[^\n"]*"

One thing you haven't looked at is an escaped ", you'll probably need to
escape those as well. That's a bit harder as \\\" is an escaped quote,
but \\\\" isn't. There isn't really a regex way for that as far as I
know. You could try:

((^|[^\\])(\\\\)*\\"

Which would lead to:

(?<!#include.*)(?<!_T)"((^|[^\\])(\\\\)*\\"|[^"\n])*"

Which does the trick.

This regex is written using the System.Text.RegularExpressions syntax
and won't work in the Visual Studio find & replace window. You could
probably write a simple commandline tool to do the trick.

Jesse
Jul 27 '07 #3
* Paul Wu wrote, On 27-7-2007 17:34:
Thanks a lot. This works well -- there is an VS 2003 addin-on
(http://www.codeproject.com/csharp/SearcherAddIn.asp) that can be used,
alberit it is buggish.
Developer
I'll start nagging DevExpress to add a feature to CodeRush.. my
favorite add-in for Visual Studio.

Jesse
>

"Jesse Houwing" wrote:
>* Paul Wu wrote, On 26-7-2007 20:48:
>> I need to replace the ascII strings in VC++ source code with unicode
compatiable strings. That is I want to replace "abc" with _T("abc") excluding
the strings in #include line or already in _T("..").

I have regular expression

1. {[^_T\(]"([^"\\]*(\\.[^"\\]*)*)"} // get strings without '_T(' prefix
2. {[^include ]"([^"\\]*(\\.[^"\\]*)*)"} //get strings without 'include '
prefix.

how can I get the intersection of these two sets so matched strings can be
replace by '_T(\1)'?

To make sure #include isn't on the line use a negative look behind:

(?<!#include.*)

To make sure you're not already in a _T"..." use a look around as well:

(?<!_T")

All other strings can be replaced (don't match the newline either,
because a string can't span lines in C++ as far as I know):

"[^"\n]*"

Combine:

(?<!#include.*)(?<!_T)"[^\n"]*"

One thing you haven't looked at is an escaped ", you'll probably need to
escape those as well. That's a bit harder as \\\" is an escaped quote,
but \\\\" isn't. There isn't really a regex way for that as far as I
know. You could try:

((^|[^\\])(\\\\)*\\"

Which would lead to:

(?<!#include.*)(?<!_T)"((^|[^\\])(\\\\)*\\"|[^"\n])*"

Which does the trick.

This regex is written using the System.Text.RegularExpressions syntax
and won't work in the Visual Studio find & replace window. You could
probably write a simple commandline tool to do the trick.

Jesse
Jul 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: Lucky | last post by:
hi guys, i'm practising regular expression. i've got one string and i want it to split in groups. i was trying to make one regular expression but i didn't successed. please help me guys. i'm...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
14
by: Chris | last post by:
I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = Can anybody help me out? Thanks for any help!
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.