Replace in RegEx?

Post your questions and problem reports here

Moderator: kfury77

Forum rules
Please try to follow these guidelines. This will help to receive faster and more accurate response.
  • Check the Support section of the corresponding product first. Chances are you will find your answer there;
  • Do not create new topics for already reported problems. Add your comments to the existing topics instead;
  • Create separate topic for each problem request. Do NOT post a number of non-related problem reports in a single topic;
  • Give your topic a meaningful title. Titles such as "A question," "Bug report" and "Help!" provide others no clue what your message is about;
  • Include the version number of the software you are using;
  • This is not an official customer support helpdesk. If you need a prompt and official response, please contact our support team directly instead. It may take a while until you receive a reply in the forum;
Post Reply
endelo
Posts: 10
Joined: Tue Jul 25, 2006 10:43 pm

Replace in RegEx?

Post by endelo »

Hey there,

I'm a new customer to Blumentals software, and I'm very pleased with the functionality and features of Rapid PHP. I do have one question however, which pertains to the Search and Replace function. I understand how to Search for a regular expression, but how do you Replace with a regular expression?

For instance, I'm trying to convert every instance of

Code: Select all

function someFunction(arguments) {
to:

Code: Select all

function someFunction(arguments)
{

By way of regular expressions, I can match every case with

Code: Select all

^function ([a-zA-Z0-9][^>]+)\(([a-zA-Z0-9][^>]+)\) \{$
, but I can't seem to get the replace function to keep my subexpressions in tact. I tried using the \1 operator, and it's no go.

Any and all help would be most appreciated. :)
User avatar
Karlis
Site Admin
Posts: 3605
Joined: Mon Jul 15, 2002 5:24 pm
Location: Riga, Latvia, Europe
Contact:

Post by Karlis »

This has already been covered in these forums. In short: this is a feature yet to come.
Karlis Blumentals
Blumentals Software
www.blumentals.net
User avatar
SimonWpt
Posts: 14
Joined: Mon Nov 13, 2006 5:10 pm
Location: Germany
Contact:

Post by SimonWpt »

Karlis wrote:This has already been covered in these forums. In short: this is a feature yet to come.
Is this feature implemented now?
User avatar
Karlis
Site Admin
Posts: 3605
Joined: Mon Jul 15, 2002 5:24 pm
Location: Riga, Latvia, Europe
Contact:

Post by Karlis »

SimonWpt wrote:
Karlis wrote:This has already been covered in these forums. In short: this is a feature yet to come.
Is this feature implemented now?
Not yet. Although it has moved by some 80 positions up in the list of suggestions to be implemented.
Karlis Blumentals
Blumentals Software
www.blumentals.net
User avatar
SimonWpt
Posts: 14
Joined: Mon Nov 13, 2006 5:10 pm
Location: Germany
Contact:

Post by SimonWpt »

Karlis wrote:Not yet. Although it has moved by some 80 positions up in the list of suggestions to be implemented.
Every serious editor should have the possibility for regex replacements.
soloowaty
Posts: 8
Joined: Tue Dec 02, 2008 3:56 am

Re: Replace in RegEx?

Post by soloowaty »

So... are we there yet?:)
User avatar
Karlis
Site Admin
Posts: 3605
Joined: Mon Jul 15, 2002 5:24 pm
Location: Riga, Latvia, Europe
Contact:

Re: Replace in RegEx?

Post by Karlis »

Yes, we are, actually. You can use ( and ) to set up variables and use $1, $2 ... to insert found occurences in the replacement text.

E.g. search for <h1>([^<]*)</h1>, replace with <h2>$1</h2> to change h1 to h2.

As far as I know this is standard perl regexpr use.
Karlis Blumentals
Blumentals Software
www.blumentals.net
soloowaty
Posts: 8
Joined: Tue Dec 02, 2008 3:56 am

Re: Replace in RegEx?

Post by soloowaty »

Thank You very much!!!
cdsaenz
Posts: 7
Joined: Sun Sep 30, 2007 7:07 am

Re: Replace in RegEx?

Post by cdsaenz »

Hi I'm a newbie on the regex thing.. Because of the changes in twitter bootstrap I want to change for example col-lg-3, col-lg-4 etc with col-md-3, col-md-4 and so on.
So I tried to enter in the search:

Code: Select all

col-lg-[0-9]
and in the replace

Code: Select all

col-md-$1
But this doesn't seem to work.. Can you point me to the right usage? Thanks!
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Replace in RegEx?

Post by Aivars »

You need to replace

col-lg-([0-9])

with

col-md-\1

provided that there is one digit after col-lg-. If there can be a multi-digit number then use col-lg-([0-9]*) instead.
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: Replace in RegEx?

Post by Aivars »

Also, $1, $2 etc was non-standard syntax that was changed to \1, \2 etc. If you want to learn more about regular expressions, this is a good site: http://www.regular-expressions.info/
Blumentals Software Programmer
Post Reply