I want to ignore whitespaces with regular expression in jmeter - html

I want to ignore the whitespace in regex for correlation in jmeter.
This is my expression given below and i need to correlate the values inside single quotes.
Here there is a space and 3 tab after the variable "var_SampleData"
var __SampleData = [['CONSN_4578', '787', '01/01/2010', 'Active']];
I tried using regular expressions like:
var __SampleData\s+ = [['(.+?)', '(.+?)', '01/01/2010', 'Active']];
var __SampleData\s* = [['(.+?)', '(.+?)', '01/01/2010', 'Active']];
var __SampleData = [['(.+?)', '(.+?)', '01/01/2010', 'Active']];
Thanks
Bichu

var __SampleData\s*= \[\['(.+?)', '(.+?)', '01\/01\/2010', 'Active'\]\];
Demo

Related

Finding a regex to match HTML

I'm trying to find a regex pattern to use with this example to match only the number values after /p/
/store/shop/en/model/brand/Heisman-On/p/15890735"target="">Heisman-on
/store/shop/en/model/brand/Heisman/p/03518616"target="">Heisman
/store/shop/en/model/brand/2tee-Cove3/p/67834675"target="">2tee-Cove3
such as :
15890735
03518616
67834675
This would do the trick:
\/p\/(\d+)
Here is a preview.
Use the first capturegroup.
Here's a way you could get the numbers:
var input = '/store/shop/en/model/brand/Heisman-On/p/15890735"target="">Heisman-on';
var regex = /\/p\/(\d+)/;
var numbers = regex.exec(input)[1];
console.log(numbers); // Output: 15890735
Try the following:
/(?:\/p\/)(\d+)/i
http://regexr.com/3blr5
Your aim would be for the $1 output

Losing leading 0s when string converts to array

I have a textInput control that sends .txt value to an array collection. The array collection is a collection of US zip codes so I use a regular expression to ensure I only get digits from the textInput.
private function addSingle(stringLoader:ArrayCollection):ArrayCollection {
arrayString += (txtSingle.text) + '';
var re:RegExp = /\D/;
var newArray:Array = arrayString.split(re);
The US zip codes start at 00501. Following the debugger, after the zip is submitted, the variable 'arrayString' is 00501. But once 'newArray' is assigned a vaule, it removes the first two 0s and leaves me with 501. Is this my regular expression doing something I'm not expecting? Could it be the array changing the value? I wrote a regexp test in javascript.
<script type="text/javascript">
var str="00501";
var patt1=/\D/;
document.write(str.match(patt1));
</script>
and i get null, which leads me to believe the regexp Im using is fine. In the help docs on the split method, I dont see any reference to leading 0s being a problem.
**I have removed the regular expression from my code completely and the same problem is still happening. Which means it is not the regular expression where the problem is coming from.
Running this simplified case:
var arrayString:String = '00501';
var re:RegExp = /\D/;
var newArray:Array = arrayString.split(re);
trace(newArray);
Yields '00501' as expected. There's nothing in the code you've posted that would strip leading zeros. You may want to dig around a bit more.
This smells suspiciously like Number coercion: Number('00501') yields 501. Read through the docs for implicit conversions and check if any pop up in your code.
What about this ?
/^\d+$/
You can also specify exactly 5 numbers like this :
/^\d{5}$/
I recommend just getting the zip codes instead of splitting on non-digits (especially if 'arrayString' might have multiple zip codes):
var newArray:Array = [];
var pattern:RegExp = /(\d+)/g;
var zipObject:Object;
while ((zipObject = pattern.exec(arrayString)) != null)
{
newArray.push(zipObject[1]);
}
for (var i:int = 0; i < newArray.length; i++)
{
trace("zip code " + i + " is: " + newArray[i]);
}

Regular Expression Help AS3?

I am working on a regular expression and I need to extract two parts of an expression that is being imported through a flashvars.
//sample data similar to what comes in from the flashvars. Note that the spaces are not after the and symbol, they are there because the html strips it.
var sampleText:String = "height1=60& amp;height2=80& amp;height3=95& amp;height4=75& amp;"
var heightRegExp:RegExp = /height\d/g; //separates out the variables
var matches:Array = sampleText.match(heightRegExp);
Now I need help isolating the values of each variable and putting them in an array...For instance, 60, 80, etc. I know I should be able to write this regular expression, but I just can't get the exec expression right. Any help would be really appreciated!
sorry for not answering the question with regexes directly. I would do this:
var keyvalues:Array = sampleText.split("& amp;");
var firstkey:String = keyvalues[0].split("=")[0];
var firstvalue:String = keyvalues[0].split("=")[1];
Would that help beside the fact, that it is not using RegEx?
Neither the =, & or the ; are special characters, so I think you can use
=|&
in a split call and then the values will be in the odd indices and the height2 style names would be in the even indices.
You can use URLUtil.stringToObject()
Something like this should work:
var s:String = "name=Alex&age=21";
var o:Object = URLUtil.stringToObject(s, "&", true);
However, if you're just getting the flashvars, you should pull them from the loaderInfo of the root.
this.root.loaderInfo.parameters;

Parsing a path in Actionscript 3?

I'm using a URLLoader to load a photo and I want to be able to display the filename of the photo based on the URLLoader's loaderInfo.url property.
Given a loader named photoLoader, what the string called fileName be?
I would take the .url property and split it into an array using the / as the delimiter. Then just grab the last item in that array to get the filename.
Code:
var pathArray:Array = photoLoader.url.split('/')
var FileName:String = pathArray[pathArray.length()-1]
with
s:String = "http:/somedomain/someurl/somefilename";
You could do
fileName = s.split('/').pop()
to return the top of the array from splitting the url at '/'
var pathArray:Array = photoLoader.url.split('/')
var FileName:String = pathArray[pathArray.length-1]
Please note that the keyword "length" is not followed by parenthesis. For arrays, it is not supposed to be a function, it is a property. On the other hand, XML lists can use the length() function.

delete leading characters

I'm a noob to actionscript so this should be easy:
How do I delete leading characters from a string? I have a string that contains (at times) both numeric & non-numeric characters. If I want to delete all the leading 9's, how would I do that?
var testVar:String = '999998gjek74k';
I want the testVar to be 'gjek74k'.
So far, I have (though not working):
var testVar:String = '999998gjek74k';
testVar.replace(/^0/g, "");
.replace doesn't modify the string. It returns the replaced string.
testVar = testVar.replace(/^\d+/, '');
(Also the pattern /^0/g is wrong, as commented by #santa).
Assuming you are testing the variables and not multiple lines:
private var testVar = testVar.replace(/^\d*(.+)$/,"$1");