Having trouble with regular expressions

General discussions about Advanced Find and Replace
Post Reply
Mike...
Posts: 2
Joined: Mon Sep 24, 2007 5:48 pm

Having trouble with regular expressions

Post by Mike... »

Hi,

I'm trying out the program and can't get a regular expression to work.

I want to batch replace the following (an example):

Code: Select all

light.9 =  7, -16.874, -30.5, 1.25 , fx_nicksmokeAI_sm_lear           // Engine 1 
light.10 = 7, -19.024, -15.0, 0    , fx_nicksmokeAI_sm_lear           // Engine 2 
light.11 = 7, -19.024,  15.0, 0    , fx_nicksmokeAI_sm_lear           // Engine 3 
light.12 = 7, -16.874,  30.5, 1.25 , fx_nicksmokeAI_sm_lear           // Engine 4
Into:

Code: Select all

// light.9 =  7, -16.874, -30.5, 1.25 , fx_nicksmokeAI_sm_lear           // Engine 1 
// light.10 = 7, -19.024, -15.0, 0    , fx_nicksmokeAI_sm_lear           // Engine 2 
// light.11 = 7, -19.024,  15.0, 0    , fx_nicksmokeAI_sm_lear           // Engine 3 
// light.12 = 7, -16.874,  30.5, 1.25 , fx_nicksmokeAI_sm_lear           // Engine 4
So basically I want to add "// " in front of every line that contains "fx_nicksmokeAI", that's the only part that sets it apart from other lines I don't want to change. The first number ranges from 0 - 19, the second is always 7, but it's not unique to lines I want to change. After that there are always three groups, the numbers can vary, positive, negative, can be 0, no decimals, 5 decimals, more, etc... After "AI" there are several combinations possible. And finally, the amount of spaces used varies from file to file.

Any help would be appreciated.

Mike...
Posts: 2
Joined: Mon Sep 24, 2007 5:48 pm

Re: Having trouble with regular expressions

Post by Mike... »

Okay, after taking RegEx 101, I've come up with:

Code: Select all

(light\.\d+\s*=\s*7\s*,\s*[-]?\d+\.?\d*\s*,\s*[-]?\d+\.?\d*\s*,\s*[-]?\d+\.?\d*\s*,\s*fx_nicksmokeAI_\w+[_]?\w*\s*[/]*\s*engine\s*\d)
Which works quite well. I've only got to tinker with the part after nicksmokeAI to accept some other variations, but that shouldn't be too difficult now. :wink:

And after some more learning and tweaking, here's the final result:

Code: Select all

(light\.?\d+\s*=\s*7\s*,\s*[-]?\d+(\.\d*)?\s*,\s*[-]?\d+(\.\d*)?\s*,\s*[-]?\d+(\.\d*)?\s*,\s*fx_nicksmokeAI_\w*([-_]?\w*)\s*(//\s*[engine]*\s*\d*)?)
The simulated runs show that the above expression finds everything it needs to find, so I'm happy. Couldn't have done it without Expresso, neat little program.

Post Reply