Re: using regular expressions with find and replace in VC++
- From: "John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx>
- Date: Tue, 8 Nov 2005 23:34:08 +1100
<jagadeeshbp@xxxxxxxxx> wrote in message news:1131449289.219062.54700@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi, Thank you for that exhaustive reply. It worked too well. But I need a bit more help.
1. What if the target is like: function(arg1, arg2+arg3, arg4) and to get function(arg1, arg4, arg2+arg3)
The original code seems to do exactly what you ask for.
2. if I need to insert a "new line" between say \1 and \2, what can I do? I tried putting \1\n\2 in the replace with string. It put something like \1n\2. How can I do this?
Please do help. TIA. -- jag
I have been playing around with this since my first post. There are a number of problems with the original (I don't use this stuff normally, so I am learning by experimentation), one of them being that it doesn't allow for an argument list that spans more than one line. A really robust solution would seem (at best) rather complicated to define and the following falls short of that. It nevertheless improves on my earlier attempt.
A simple approach is to allow for any character in the function argument except , and \). This will allow them to act as a delimiters. [^\),] denotes any character except \) and , and \n. We want to allow \n, so we add that in, making our expression for an argument
[^\),]|\n
We want any number of these, so we use
([^\),]|\n)*
These must be mapped to \1, \2 etc., so we enclose the expression on braces:
{([^\),]|\n)*}Substituting this for the various function arguments, we arrive at:
func\({([^\),]|\n)*},{([^\),]|\n)*},{([^\),]|\n)*}\)This seems to work in most cases in terms of matching arguments. (I note that you have gone from using func to using function; naturally this must match too.) It will fail if you make use of , or \) within an argument.
As for inserting new lines, putting \n in the replace string should work (it does for me). Note, however, that the above search string will capture any newline characters in the original function and insert them in the modified one (albeit perhaps in a different position).
--
John Carson
.
- Follow-Ups:
- Re: using regular expressions with find and replace in VC++
- From: jagadeeshbp
- Re: using regular expressions with find and replace in VC++
- References:
- using regular expressions with find and replace in VC++
- From: jagadeeshbp
- Re: using regular expressions with find and replace in VC++
- From: Ulrich Eckhardt
- Re: using regular expressions with find and replace in VC++
- From: jagadeeshbp
- Re: using regular expressions with find and replace in VC++
- From: John Carson
- Re: using regular expressions with find and replace in VC++
- From: jagadeeshbp
- using regular expressions with find and replace in VC++
- Prev by Date: Re: using regular expressions with find and replace in VC++
- Next by Date: Re: using regular expressions with find and replace in VC++
- Previous by thread: Re: using regular expressions with find and replace in VC++
- Next by thread: Re: using regular expressions with find and replace in VC++
- Index(es):
Relevant Pages
|