JMeter 5 - Failed to replace text - replace

I'm trying to use JMeter 5.0 replace feature
Search feature has been improved to allow you to iterate in the tree over search results and do necessary replacements through Next/Previous/Replace/Replace/Find buttons
I can search and find occurrences and find text, but I can't replace it using Replace/Replace All/Replace & Find
Replace All report as Replaced 0 occurrences
Replace or Replace & Find returns error:
2018-09-26 10:23:49,276 ERROR o.a.j.JMeter: Uncaught exception:
java.lang.ArrayIndexOutOfBoundsException: null
Example trying to replace text:
How should I use the replace feature?

This looks like a bug opened under:
https://bz.apache.org/bugzilla/show_bug.cgi?id=62767
Replacement is not available in JSR223 Test Elements but search should not fail.
Note that Search/Replace feature is not a full search/replace feature as it is intended for correlation:
so replacement is limited to certain elements (Header Manager, HTTP Request, AjpSampler, AccessLogSampler)
replacement only concerns the values and not the parameter/header names

Workaround:
Just take a backup before doing this for safety purpose.
Close the jmx file in JMeter.
Open the jmx file in Notepad++ (it will be like xml)
Search and replace whichever you want to and Save
Open the jmx with JMeter, you can find the replaced text

Related

Use advanced filter for a series of similar 'search and replace' filters

I have multiple Search and Replace filters that remove a sequence of numbers from the page path.
For example Search String
/abc/.*[0-9]/
/def/.*[0-9]/
/ghi/.*[0-9]/
/jkl/.*[0-9]/
/mno/.*[0-9]/
Replace String
/abc/
/def/
/ghi/
/jkl/
/mno/
Can I use an Advanced filter instead?
Of course you can, just replace all numeric subfolders with nothing. Use the following regular expression to get them:
/[0-9]*/
With just one filter you will get the same result (and scalable)
**** EDIT
Not sure how accurate will Google Analytics be with repeating elements in a regular expression. I've noticed in your example that not all subfolders follow the same pattern (end /)
I think, the best approach to this situation could be using virtual pages. You can strip/clean the URLs with your programming language and create clean paths to be sent to Analytics.
The easiest way would be with Google Tag Manager: javascript regular expression + virtual pages

Regular expression to find non-encapsulated text that's also not commented out

I'm working on migrating a database into a sql project, and need to replace all instances of cross-database calls with a SQLCMD variable, and am struggling to write a regex to help me find the places I still need to update.
In the SQL, we have the following:
MyOtherDatabase.MySchema.MyTable
[MyOtherDatabase].MySchema.MyTable
Which I need to change to:
[$(MyOtherDatabase)].MySchema.MyTable
So far, I've come up with the following regex:
([^(]M|^M)yOtherDatabase
Which finds all places where "MyOtherDatabase" is used, and hasn't been replaced with the variable.
HOWEVER, it's also picking it up in SQL comments, such as:
-- I don't want to find MyOtherDatabase in this line
and
FROM ADifferentPlace -- Used to be MyOtherDatabase
If this was only a few instances, I'd live with it, but I've currently got 560 matches, most of which are one or the other of the above, making it very easy for human error to get in the way.
I'm using this regex in the "Search" box within Visual Studio 2015, with the "use regex" checkbox ticked.
any advice would be helpful!
Edit
Also need to NOT find the following:
from MyTable -- from MyOtherDatabase.MySchema.MyTable
If your environment supports variable-length negative lookbehinds, you could use the following to avoid matching any commented section :
search for (?<!--.*)MyOtherDatabase(?=]?\.)
replace by $(MyOtherDatabase)
If it doesn't, you can still match lines from the start :
search for ^((?:[^-]|-[^-])*)MyOtherDatabase(]?\.)
replace by \1$(MyOtherDatabase)\2

RegEx to delete all XML data outside of specified tags

I am using the latest and greatest version of NotePad++. Is it possible for a RegEx to delete all text and tags I don't need and only leave behind text and tags I need? The tags I need to remain look like this:
<warning>I need this text to remain intact together with accompanying tags.</warning>
There must be around 500 of these WARNING tag pairs nested within a variety of XML levels. I would like the RegEx to delete all data that exists outside of these WARNING tags but not the opening and closing warning tags themselves or the text within the tags. Below are four different RegEx variations I tested out and they all eliminate the text located within the warning tags after performing a Find&Replace operation therefore they are no help:
<warning>[^<>]+</warning>
<warning>[^>]+</warning>
<warning>(.+?)</warning>
<warning>.*?</warning>
I would tremendously appreciate any help that will assist me in developing a RegEx that will perform the data clean up task I need to perform.
I use notepad++ regex find and replace below seems works for me. Remember to select regular expression.
Search and replace both regex below with empty. Require 2 steps though, not perfect yet
1st replace remove all lines that not startswith warning
2nd replace remove all the empty lines leaving only lines with warning
^(?!\s*?<warning>).*?$
^\s*

Using the Ace Code Editor, can I search and return results to variable?

I'm using the Ace Code Editor for a Chrome extension. I know how to perform a search and replace, it's pretty well documented here: http://ace.c9.io/#nav=howto
But is there a way I can perform a search matching a regex expression and just have the results return and stored in a variable? I'm trying to guess the tab indenting on an existing document, so I want to search the document for leading whitespace on each line, and be able to compare results
Ace have built in module for detecting indentation see https://github.com/ajaxorg/ace/blob/master/lib/ace/ext/whitespace.js#L105.
You can see it in action in kitchen-sink demo. It is called from https://github.com/ajaxorg/ace/blob/master/demo/kitchen-sink/demo.js#L344
As about using the search api for this, it will be slow, using regex like Ace does is the correct way.

Filter by regex example

Could anyone provide an example of a regex filter for the Google Chrome Developer toolbar?
I especially need exclusion. I've tried many regexes, but somehow they don't seem to work:
It turned out that Google Chrome actually didn't support this until early 2015, see Google Code issue. With newer versions it works great, for example excluding everything that contains banners:
/^(?!.*?banners)/
It's possible -- at least in Chrome 58 Dev. You just need to wrap your regex with forward-slashes: /my-regex-string/
For example, this is one I'm currently using: /^(.(?!fallback font))+$/
It successfully filters out any messages that contain the substring "fallback font".
EDIT
Something else to note is that if you want to use the ^ (caret) symbol to search from the start of the log message, you have to first match the "fileName.js?someUrlParam:lineNumber " part of the string.
That is to say, the regex is matching against not just the log message, but also the stack-entry for the line which made the log.
So this is the regex I use to match all log messages where the actual message starts with "Dog":
/^.+?:[0-9]+ Dog/
The negative or exclusion case is much easier to write and think about when using the DevTool's native syntax. To provide the exclusion logic you need, simply use this:
-/app/ -/some\sother\sregex/
The "-" prior to the regex makes the result negative.
Your expression should not contain the forward slashes and /s, these are not needed for crafting a filter.
I believe your regex should finally read:
!(appl)
Depending on what exactly you want to filter.
The regex above will filter out all lines without the string "appl" in them.
edit: apparently exclusion is not supported?