473,811 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2092
* 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.Reg ularExpressions 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.Reg ularExpressions 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.Reg ularExpressions 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
5176
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 testMyColumn{1, 100}Test Basically I want the regular expression to add the word test infront of the
4
3235
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 over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no specific format and I have to detect and remove them using a list of strings that may appear as...
3
2308
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 id="valValidEmail" runat="server" ControlToValidate="txtEmail" ValidationExpression="^(+)(\.+)*@(+)(\.+)*(\.{2,4})$"
18
3047
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
3834
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 want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
3
1352
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 using .NET 2.0's Regular expression class. here is the string.
25
5180
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 (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
6
2240
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: this is a description Slot: slot2
14
2281
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
4390
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 the first regular expression that matches the string. I've gor the regular expressions ordered so that the highest priority is first (if two or more regular expressions match the string I want the first one returned) The code that does this has...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.