tags:

views:

132

answers:

6

For example:

$lang['Select Project'] = 'Select Project OK';

$lang['Project'] = 'Project';

I want to find only the instances of the word 'Project' not contained within the square brackets.

I'm using cold fusion studio's extended replace utility to do a global replace.

Any suggestions?

Code Sample Follows:

    <?php
$lang['Project Message Board']               = 'Project Message Board';
$lang['Project']           = 'Project';
$lang['Post Message']         = 'Post Message';
$lang['To']          = 'To';
$lang['Everyone']          = 'Everyone';
$lang['From']              = 'From';
$lang['Private Messsage']         = 'Private Messsage';
$lang['Note: Only private message to programmer']         = '[ Note: Please enter programmers id for private message with comma separate operator ]';
$lang['Select Project']       = 'Select Project';
$lang['message_validation']      = 'Message';
$lang['You must be logged in as a programmer to post messages on the Project Message Board']    = 'You must be logged in as a programmer to post messages on the Project Message Board';
$lang['Your Message Has Been Posted Successfully']                               = 'Your message has been posted successfully';
$lang['You must be logged to post messages on the Project Message Board']           = 'You must be logged to post messages on the Project Message Board';
$lang['You must be post project to invite programmers']                             = 'You must be post project to invite programmers';
$lang['You must be logged to invite programmers']                                   = 'You must be logged to invite programmers';
$lang['There is no open project to Post Mail']                                                  = 'There is no open project to Post Mail';
$lang['You are currently logged in as']='You are currently logged in as';
$lang['Tip']='Tip: You can post programming code by placing it within [code] and [/code] tags.'; 
$lang['Submit']='Submit';
$lang['Preview']='Preview';
$lang['Hide']='Hide';
$lang['Show']='Show';
$lang['You are currently logged in as']='You are currently logged in as';
A: 

While it's not clear what instances you want to find exactly, this will do:

^.+? = (.+?);

But you might consider using simple string manipulation of your language of choice.

edit

^.+?=.+?(Project).+?;$

will only match lines that have string Project after the equal sign.

SilentGhost
Please read question after editing as I didnt make myself clear - many thanks!
Dave
thx for help but this matches entire page. So if I do a replace it doesnt work- any ideas?
Dave
you should post code you're using. it works just perfectly for me.
SilentGhost
Code posted also read comments from Kips response -any ideas?
Dave
I've updated my code
SilentGhost
A: 

Thx for help. Not sure what is unclear? I just want to find all instances of the word 'Project' but only instances to the right of the equals sign (i.e. not included in square brackets). Hope that helps.

Dave
please edit your question to add this information and then delete this non-answer. This is not a forum.
SilentGhost
A: 

[^\[]'[^'\[\]]+'[^\]] seems to accomplish what you want!

This one: [^\[]'[^'\[\]]*Project[^'\[\]]*' will find all strings, not inside of the file that are contained in quotes, and contain the word project.

Another edit: [^\[]'(?<ProjectString>[^'\[\]]*Project[^'\[\]]*)'[^\]] This one matches the string, and returns it as the group "ProjectString". Any regex library should be able to pull that out sufficiently.

Erich
can you update to so I'm only finding the instances of the word 'project' not contained within square brackets.
Dave
You want any sentence that contains project, correct? Not just the word "project" a dozen times, right?
Erich
A: 
Kip
in what regex flavour did you test this code? because it won't work in most of the languages.
SilentGhost
sounds good but cant get this working - it doesnt seem find any instances at all?
Dave
you're right, look-behinds usually have to be fixed length
Kip
thx yes - your right this is what i want to do. However, is there anyway we can reverse this logic - to find instances of the word 'Project' that are not contained within square brackets? I am using cold fusion studio extended replace tool to carry out the global replace.
Dave
Hi Kip - this doesnt work but I'm guessing its because it will always find an instance followed by "']" because it goes on to the next line...???
Dave
@Dave: My code finds "Project"s which are **not** to the left of an equals sign. If you specifically want it to find "Project"s which are not to the left of "`']`", you could use this regex: `/Project(?![^'\]]*'\])/`
Kip
@Dave: hmm... can you see if there is a way to make cold fusion studio only execute the regex on each individual line, instead of on the whole file at once? Look for an option called "multi-line mode" or something like that maybe
Kip
understood - you would think this would work, but I think it is not working because the find/replace utility is viewing the whole file rather than individual lines?
Dave
no it doesnt have one...
Dave
i dont have to use CF studio if you recommend something else? - I have got dozens of files with hundreds of instances....!
Dave
Maybe one of these would work: `/Project(?![^'\]\n]*'\])/` and `/Project(?![^=\n]*\=)/` I'm adding \n to the list of characters that can't appear between Project and the next `']` or `=`
Kip
Looking at this page (http://www.adobe.com/livedocs/coldfusion/5.0/Using_ColdFusion_Studio/language5.htm), you may have to try one of these: `/Project(?![^'\]#chr(13)##chr(10)#]*'\])/` or `/Project(?![^=#chr(13)##chr(10)#]*\=)/`
Kip
no joy i'm afraid...
Dave
Have you used Eclipse? That lets you do regex across a lot of files. It would be a big download just for this, but if you've got hundreds of files it may be worth it. In Eclipse the versions with \n work: `/Project(?![^'\]\n]*'\])/` or `/Project(?![^=\n]*\=)/`
Kip
Downloaded Eclipse and after a while got it work - huge thanks for all your help!!!
Dave
+2  A: 

A regexp for 'Project' to the right of an equals sign would be:

/=.*Project/

a regexp that also does what you ask for, 'Project' that has no equals sign to its right would be:

/Project[^=]*$/

or a match of your example lines comes to:

/^\$lang['[^']+']\s+=\s+'Project';$/

By placing 'Project' in brackets () you can use that match in a replacement, adding the flag /g finds all occurences in the line.

rsp
Very clever even though this is not exactly what he was after. It would solve his problem though. :)
Robert Koritnik
A: 

This actually looks like a tricky problem. Consider

[blah blah [yakkity] Project blah] Project [blah blah] [ Project

This is a parsing problem, and I don't know of any way to do it with one regex (but would be glad to learn one!). I'd probably do it procedurally, eliminating the pairs of brackets that did not contain other pairs until there were none left, then matching "Project".

Beta
OP doesn't have that kind of issues. there is no need to complicate things.
SilentGhost