How would one go about using replace in netbeans to modify a PHP script with lots of $_POST[].
For better security it would be a good idea to replace all these $_POST[]
with sanitize($_POST[]) where sanitize is a function that sanitizes user input.
So I could use Replace and search for $_POST[''] and replace with sanitize($_POST['']).
But how do you keep the variable name within each $_POST[''] while adding the closing parenthesis?
For example $_POST['name'] and $_POST['action'] need to become sanitize($_POST['name']) and santize($_POST['action']) respectively.
I am not a PHP programmer or a Regex master but in my very limited test this seemed to work.
Select the project and then choose Edit -> Replace. Choose "Regular Expression" in the drop down list, set containing text to \$_POST\[(.*)\]and replace with to sanitize(\$_POST[$1])
Related
This is a question about the Matlab editor. I have several recurrent texts in my script such as:
e_{pos}=%.3f, e_{vel}=%.3f\n
I want to remove the curly brackets around these terms, so I use the Find/Replace dialog to replace \{(\w+)\} with $1:
But, the editor inserts a literal $1 instead of the matched text (vel or pos). I know some editors use different characters than $ so I also tried \1 and #1 but they did not work either. The documentation does not mention it.
So, is it possible to replace a matched group in the Matlab editor? How can I do it?
Note: I am not asking for the Matlab code to do this, I want to do it in the editor.
Thank you!
I'd like to add a suffix to all occurrences of a variable in a file (eg. pluralizing a variable number --> numbers).
VSCode offers a multiselect option thru the default "cmd+d", or editor.action.addSelectionToNextFindMatch. However, after I do this over all occurrences of number, the entire variable is selected. I really just need the cursor to be at the very end, so I can add an s. I would like not have to retype numbers.
How can I achieve this?
As an alternative, I use a regex:
\b(var1|var2|var3)\b
And I replace it with the same content $1 (since I capture the variable name in a group with ()) followed by 's': $1s
I would just copy the variable first. So:
Double-click your variable and Ctrl-C
Ctrl-F2 selects all occurences
Ctrl-V and add your 's'
The regex method is better if you have a few variables to change, but not if you have only one or two to change. Really simple to create a macro if you would be doing this a lot - you could get it down to a single keychord.
[This unfortunately selects occurrences of var1 and someOtherVar1 (the Var1 part) - so if this is a problem better to use a regex as it is easier to exclude instances of the var1 term appearing within another word, like someVar1 that you do not intend to change.]
I want to use the Search and Replace dialogue in Rubymine, or something similar to replace something like "Scenario:" with "#Desktop\nScenario"
I'm trying to replace every instance of Scenario: in a large Cucumber test suite with
#desktop
Scenario:
Any best ways to do this?
Update:
Thanks to #ryan2johnson9 comment, I realise there's now an easier option (tested on 2017.3).
By clicking on the "New Line" (or using the shortcut Ctrl+Shift+Enter / Alt+Enter), the input becomes multilines.
Original Answer
In the search and replace box, if you tick the "Regex" option you can do:
Search: "Scenario:"
Replace by: "#desktop\nScenario:"
The only trick is to tick the "Regex" option :)
Rubymine has macros (http://www.jetbrains.com/ruby/webhelp/binding-macros-with-keyboard-shortcuts.html) but I dont think they are powerful enough for this example.
It's possible that you could solve it with some elaborate feature hidden inside Rubymine, but I think it would be a lot easier to do this with a tool like perl/sed from the Terminal. If you are using Windows I assume you could search the net and find a text search/replace tool that fits your need.
In OSX I there are a bunch of Text Substitutions app too.
I would go that route since Rubymines macro tool isnt up to the task.
Here's a cheap and sleazy alternative:
Copy a newline character from between two empty lines in the file being edited. Temporarily add two empty lines if you don't have any.
Set up search/replace and enter the string you want to replace into the search text input box.
Paste the newline you just copied into the replacement text box plus whatever other text you want. You will be able to see the height of the replacement text input box grow vertically by one line due to the newline.
Perform the search/replace.
For this, the use of the Rubymine regex is optional.
I'm wondering, is there a way that you can do a search for all words that have the word "pPath" in them and replace them with "mutablePath" in Xcode. For instance, there are certain instances where there could be pPath_0 or pPath_50, I just want to replace them all with "mutablePath". Is there a regular expression I can use for this if it's possible?
EDIT #1: I mean to actually replace the whole word pPath_50 or (any word that has pPath in it) with mutablePath. Doing a simple find and replace will only replace the word "pPath" with "mutablePath".
EDIT #2: I found out that if you click the magnifying glass next to the search bar, then click "Show Find Options", you can select "Regular Expression" from a pull down menu and use it to do a search for a regular expression. I'm assuming that the regular expression language used for this is common to other things, does anyone know what the regular expression is to search for any word that has pPath at the beginning of it?
I found that you actually can use regular expressions on find and replace in Xcode 4.3. Simply click on the magnifying glass next to the search box (or the area where you enter in the text to search). Select "Show Find Options", then under "Style" choose "Regular Expression". I'm not too familiar with regular expressions, but I believe it uses syntax that is similar to a lot of other modules that implement them. For instance, I was able to solve my problem using "pPath_\w*".
Yes - Go to Search Navigator (left pane) - Click on the drop down for 'Find' and you will see replace.
I have 500+ program files in a project. I would like to replace a string "vector" to "std::vector" in all the files. How can I do this in Eclipse? I am using Eclipse CDT Helios.
(One option is to use Search->Search and enter the string to be replaced and press "Replace" button. But the problem here is that, it will replace "vectorOfPoints" and "pointsVector" also.)
I guess you could just search for ' vector ' and replace it with ' std::vector ' as you described yourself. Instead make sure there is a space leading and ending your search, so you take only the single word vector.
Maybe you'll only need a space in the end, if vector occurs at the start of a new line. Also make sure your search is case sensitive.
By using Search -> File... from the menu you can search for strings in any files. As Containing text you should use a regular expression so that vectorOfPoints will not match. Then click on Replace... and Eclipse will look up all occurrences. Here you can even have a preview before executing the replace operation.
You can use Edit->Find/Replace and from options select whole world so it will not replace vectorOfPoints