I would like to write a regular expression that catch Encoded Words parts from email MIME message string (eml). for example, this is part of email:
<div dir=3D"ltr"><br clear=3D"all"><div><div dir=3D"ltr"><div style=3D"dire=
ction:rtl">-------------</div><div style=3D"direction:rtl">=D7=91=D7=91=D7=
=A8=D7=9B=D7=94,</div><div style=3D"direction:rtl">=D7=90=D7=91=D7=99=D7=A2=
=D7=93 =D7=9B=D7=94=D7=9F</div></div></div>
</div>
--20cf3003bc2e044e980500f755dc--
--20cf3003bc2e044e9d0500f755de
Content-Type: text/plain; charset=US-ASCII; name="EhudBanay.txt"
Content-Disposition: attachment; filename="EhudBanay.txt"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_hz0z4us30
aHR0cHM6Ly93d3cuZmFjZWJvb2suY29tL2wucGhwP3U9aHR0cHMlM0ElMkYlMkZ3d3cucmFwaWRz
aGFyZS5jb20lMkZmaWxlcyUyRjM4NzAxNTA2MDclMkZFaHVkX0JhbmFpXy1fVGlwX1RpcGFfXzE5
OThfLnJhciZoPTdBUUZRb0RMQQ0KDQpodHRwczovL3d3dy5mYWNlYm9vay5jb20vbC5waHA/dT1o
dHRwcyUzQSUyRiUyRnd3dy5yYXBpZHNoYXJlLmNvbSUyRmZpbGVzJTJGMzk5MzMyNjg1MSUyRkVo
dWRfQmFuYWlfLV9UYWhhdF9TaWFoX0hhWWFzbWluXzE5ODkucmFyJmg9QkFRRWhJY3djDQoNCmh0
dHBzOi8vd3d3LmZhY2Vib29rLmNvbS9sLnBocD91PWh0dHBzJTNBJTJGJTJGd3d3LnJhcGlkc2hh
cmUuY29tJTJGZmlsZXMlMkYzMjQwMTM5MTMyJTJGRWh1ZF9CYW5haV8tX1Jlc2lzZXlfTGFpbGFf
MjAxMS5yYXImaD1RQVFHN0pGWXUNCg0KaHR0cHM6Ly93d3cuZmFjZWJvb2suY29tL2wucGhwP3U9
aHR0cHMlM0ElMkYlMkZ3d3cucmFwaWRzaGFyZS5jb20lMkZmaWxlcyUyRjE5NTE2ODA4MTglMkZF
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mX1RoZV9OaWdodF9fMjAxMV8ucmFyJmg9Y0FRRlRZQ1pTDQoNCmh0dHBzOi8vd3d3LmZhY2Vi
b29rLmNvbS9sLnBocD91PWh0dHBzJTNBJTJGJTJGd3d3LnJhcGlkc2hhcmUuY29tJTJGZmlsZXMl
MkYzMTQ3NzUzNzAwJTJGRWh1ZCUyNTIwQmFuYWklMjUyMC0lMjUyMEtlZXAlMjUyMERyaXZpbmcu
cGFydDEucmFyJmg9S0FRRWtPUkZTDQoNCmh0dHBzOi8vd3d3LmZhY2Vib29rLmNvbS9sLnBocD91
PWh0dHBzJTNBJTJGJTJGd3d3LnJhcGlkc2hhcmUuY29tJTJGZmlsZXMlMkYxNzc1NDI5NDY3JTJG
RWh1ZF9CYW5haV8tX0FuZV9MaV9fMjAwNF8ucmFyJmg9dkFRRWlEWXFu
I didn't manage to do it with regular expression so i tried to use the following line which always start with "--" and ends with "--". notice that before the wanted part there is always an empty line.
I tried: "(\s).*(--)$" but it returns only the following line.
Can someone please help?
It sounds like you're trying to parse multipart/mixed email. There are libraries in most languages to do this already. If you want to write your own I'd suggest following the structure of a multipart message.
Find the boundary defined in the content-type header
Split the message into parts delimited by the boundary (prefixed by --).
For each part seek to the first instance of two consecutive line breaks that denote the end of the headers.
While regular expressions might be helpful for some part of this. I'm not sure its the right tool to parse a structured message.
You can use this regex:
\n\s*\n\K(?:[^-]{2})*.?(?=\n--)
Online demo
Related
I am using REST-API for testing
I am stuck where I am checking the response with some specific string.
please refer below info
I got the response from a request is
{
"clusters":[
{
"id":10,
"name":"HP2",
"status":2,
"statusDisplay":"HParihar#4info.com",
"lastModifiedBy":"HParihar#4info.com",
"lastModifiedTime":"06/08/2017 23:42",
"sitesAppsCount":0
},
{
"id":799,
"name":"Regression_cluster_111_09",
"status":2,
"statusDisplay":"admin#4info.net",
"lastModifiedBy":"admin#4info.net",
"lastModifiedTime":"07/11/2017 08:19",
"sitesAppsCount":0
}
]}
and I wanted to match just
"name":"Regression_cluster_111_09",
"status":2,
"statusDisplay":"admin#4info.net",
"sitesAppsCount":0
right side values I'll be keeping as hard coded.
any guesses?
Since you are only checking those 4 parameters are in response or not.
Do no use regex for this.
Use jsonObject's find key/value feature.
Check whether the values to the keys are there.
If key/value is null, the parameter is not in response.
I got my answer
I used the following regex
"name":"Regression_cluster_111_09","status":2,"statusDisplay":"admin#4info.net","lastModifiedBy":"[a-z]+#[0-9a-z]+\.[a-z]+","lastModifiedTime":"[0-9]{2}\/[0-9]{2}\/[0-9]{4}\ [0-9]{2}:[0-9]{2}","sitesAppsCount":0
or I can simply use
"name":"Regression_cluster_111_09","status":2,"statusDisplay":"admin#4info.net",.+"sitesAppsCount":0
thank you all
I am sending First request to server:
POST http://192.168.7.101/r2.web/Planning/Scheduling/TimelinefromR3 -->(A)
I have written Regular Expression extractor((?<=\"Values":")(.*?)(?=\")) to extract Resourcenames like "Ray Gwilliams" and "James Mark" from the response of (A),
Now, I have another request(as mentioned below) to which, I need to pass all the Resource names("Ray Gwilliams" and "James Mark") extracted above.
Please let me know how to achieve this.
http://192.168.7.101/R2.Web/Planning/Scheduling/SchedulesAndGroups
POST data:
[{"ColumnName":"CONTACTNAME","ColumnIId":0,"UdfIId":null,"ConditionIId":0,"OperatorIId":1,"SequenceNo":0,"Values":"Ray Gwilliams
","Lookup":null,"LookupIId":0,"LookupSource":0,"LookupType":0,"MultipleOperatorIIds":null,"MultipleValues":null,"ColumnDataType":null},{"ColumnName":"CONTACTNAME","ColumnIId":0,"UdfIId":null,"ConditionIId":0,"OperatorIId":1,"SequenceNo":0,"Values":"James Mark
","Lookup":null,"LookupIId":0,"LookupSource":0,"LookupType":0,"MultipleOperatorIIds":null,"MultipleValues":null,"ColumnDataType":null}
I have not used the regular expression but if you use the JSON Extractor element and put the extracted value into a variable, you would just add the variable into the 2nd POST request. For example:
POST data:
[{"ColumnName":"CONTACTNAME",
"ColumnIId":0,"UdfIId":null,"ConditionIId":0,
"OperatorIId":1,"SequenceNo":0,
"Values":"${variable1} ","Lookup":null,"LookupIId":0,
"LookupSource":0,"LookupType":0,
"MultipleOperatorIIds":null,"MultipleValues":null,
"ColumnDataType":null}, {"ColumnName":"CONTACTNAME",
"ColumnIId":0,"UdfIId":null,
"ConditionIId":0,"OperatorIId":1,
"SequenceNo":0,
"Values":"${variable2} ","Lookup":null,"LookupIId":0,
"LookupSource":0,"LookupType":0,
"MultipleOperatorIIds":null,
"MultipleValues":null,"ColumnDataType":null}
Tip: To get the value you want extracted, use jmeter's JSON Path Tester in the View Results in Tree listenter element or this helper tool: http://jsonpath.com/
I need to extract a username from the log below via regex for a log collector.
Due to the nature of the logs we're getting its not possible to define exactly how many forward slashes are going to be available and I need to select a specific piece of data, as there are multiple occurances of similar formatted data.
Required data:
name="performedby" label="Performed By" value="blah.com/blah/blah blah/blah/**USERNAME**"|
<46>Jun 23 10:38:49 10.51.200.76 25113 LOGbinder EX|3.1|success|2016-06-23T10:38:49.0000000-05:00|Add-MailboxPermission Exchange cmdlet issued|name="occurred" label="Occurred" value="6/23/2016 10:38:49 AM"|name="cmdlet" label="Cmdlet" value="Add-MailboxPermission"|name="performedby" label="Performed By" value="blah.com/blah/blah blah/blah/USERNAME"|name="succeeded" label="Succeeded" value="Yes"|name="error" label="Error" value="None"|name="originatingserver label="Originating Server" value="black"|name="objectmodified" label="Object Modified" value="blah/blah/USERNAME"|name="parameters" label="Parameters" value="Name: Identity, Value: [blah]Name: User, Value: [blah/blah]Name AccessRights, Value: [FullAccess]Name: InheritanceType, Value: [All]"|name="properties" label="Modified Properties" value="n/a"|name="additionalinfo" label="Additional Information"
I've tried a few different regex commands but I'm not able to extract the necessary information without exactly stating how many / there will be.
blah\.com[.*\/](.*?)"\|name
Try this :
blah\.com.*\/(.*?)"\|
Check here
If your username format is this :
value="abc.xyz/something/something/..../USERNAME"
then use this :
\..*\/(.*?)"
check here
Possible solution:
value="[a-z\.\/]*\/(.*)"
(The first capture group is the username)
Working example:
https://regex101.com/r/qZ0zC8/2
Mayby like this?
blah.(\w+\/)+\K([\w]+)
It's catch Username but since it's between ** so I also match them
tested in notepad++
(Edit: The answer is to use check 'Encode?'option in the HTTP Request. Please see Vinoth's Edit 2 and comment below, thanks!)
This is interesting!
I'm trying to parse a HTTP response which has (let's give concrete example,
bigH:"2a3a6CEH+iJakQpQtPm8efv"
Using Regular Expression Extractor when I try
bigH:"(.+?)"
it extracts the string but replaces all the "+" in the string with space. That is, instead of
"2a3a6CEH+iJakQpQtPm8efv"
it gives me:
"2a3a6CEH iJakQpQtPm8efv"
Note the space between H and i.
How can I stop it from replacing the "+" with a space? I'd really appreciate if someone can give an explanation also.
Btw, I tried (.+?) and (.\++?) and even ([.|\+]+?) - didn't work :(
Thanks,
--Ishtiaque
Updating with screenshots below:
Adding screenshots:
POST Response data:
After parsing with regular expression extractor in JMeter:
Side by side in Notepad++:
'Raw' tab shows the '+'s:
'HTTP' tab does not:
As you get the response in JSON format, I would go with JSON Path Extractor.
It seems to be a much easier approach than using Regular expression.
Below JSON Path should take care of getting the encoded string from your JSON & You should be able to access using ${bigH}.
Check this for more details (scroll down for JSON Path extractor details).
EDIT:
I was wrong that You get the response in JSON format. Are you trying to access - bigH:"XXX" - from script tag? For this, We have to use Regular expression extractor only or Beanshell.
<script type='text/javascript' charset='utf-8'>
registerSubmit(document.forms[0].elements['SubmitTopButton']);
registerSubmit(document.forms[0].elements['SubmitBottomButton']);
(function($) {
$(".wb_tsauthall").wb_tsauthall({
auth : "Authorize All",
unauth : "Unauthorize All",
locMsgKeys : []
});
$(".wb_newedit").wb_newedit({
labels:['Job','Code','Work Premium','Flat Rate','Premium','Shift','Sched Times','LTA','Sched Times w Breaks','Delete Details','Employee Holiday','Work Detail','Schedule Detail'],values:[105,103,200,206,204,450,401,500,461,199,900,100,460],bigH:"PVxUbYIODBT31j8IZnPGxF/9O1iuKAkFzTO9WhXu8An8hAUa22tLiWrEHz8v9SIu/NXZH1a5IxO0xYeNwRIYM+3n1kNsrESnhiAYhwhCiqUY9mI4hvEPgAOx7B+MEB8iSIUyNGNZbeGx9nSogFYpNrzmCXirW7Nm9Tn7owPKHmc8dOf5SZ+eDzAOHIB8+5YzQ3bIdFoe60hOMkyd7FiUXtwPcNMUFEjOSMs9JhgIHTE4agpCdbFb6SLuSuLoO9rqxj+9GovUbzTmrxj4faBKZVATNN7iIFyDZHYAZuZRcPJBdUJ1xNHMCWyPZ4p2/Yk0Q0ujdKJbJw9NFysikZgBFNEhNXEA4w8HL1ycYCmZDgSUW1GsumDAKh0Brq3K8Kh2akep8YEjDMWipKgSPaNx3CVY4lf87e0oK70nK/zKGkmpWFvyMnxbkJtWmeuxmPgRZgg2lYbZXFauD1AidnQQhPULJTTV+P+Xkk9PYm3ZkIEcDnYJUmPg/D3iuwg84m2IZatFTdjiNuDAcGNKptTd54yMgohN87c3sRMiZlSY/r88u+Le3BKWJqyl7Xai7Odqz366DFgOzdPi92LnSaggKX++hy+Z04kjyfSZOUYWmiWlc38SUdeTq2v15egig2mMkSLMaUnHagk="
});
$("#codeSummaryBar").wb_expandableframe({
iframe : contextPath + '/dailytimesheet/summaryInline.jsp'
});
$("#codeSummaryBar").click(function(){$("#codeSummaryBar_expand_collapse_icon").toggleClass("collapse expand");});
$("#codeSummaryBar").click();
$("#selectionBar").wb_expandableframe({
iframe : contextPath + '/dailytimesheet/dailySelectInline.jsp',
onExpand : function() {
$(".selectionBarControl").css("visibility", "hidden");
$("#expand_collapse_icon").removeClass("expand").addClass("collapse");
},
onCollapse : function() {
$(".selectionBarControl").css("visibility", "");
$("#expand_collapse_icon").removeClass("collapse").addClass("expand");
}
});
DTS.onload();
})(jQuery);
</script>
EDIT 2:
I doubt that you might have checked the Encode in the HTTP Request.
Uncheck
Try with the regular expression ([a-zA-Z0-9+]+)
Wanting to capture a variable called scanNumber in the http response loking like this:
{"resultCode":"SUCCESS","errorCode":null,"errorMessage":null,"profile":{"fullName":"TestFirstName TestMiddleName TestLastName","memberships":[{"name":"UA Gold Partner","number":"123-456-123-123","scanNumber":"123-456-123-123"}]}}
How can I do this with a regular experssion?
The tool I am using is Gatling stress tool (with the Scala DSL)
I have tried to do it like this:
.check(jsonPath("""${scanNumber}""").saveAs("scanNr")))
But I get the error:
---- Errors --------------------------------------------------------------------
> Check extractor resolution crashed: No attribute named 'scanNu 5 (100,0%)
mber' is defined
You were close first time.
What you actually want is:
.check(jsonPath("""$..scanNumber""").saveAs("scanNr")))
or possibly:
.check(jsonPath("""$.profile.memberships[0].scanNumber""").saveAs("scanNr")))
Note that this uses jsonPath, not regular expressions. JsonPath should more reliable than regex for this.
Check out the JsonPath spec for more advanced usage.
use this regex to match this in anywhere in json:
/"scanNumber":"[^"]+"/
and if you want to match just happens in structure you said use:
/\{[^{[]+\{[^{[]+\[\{[^{[]*("scanNumber":"[^"]+")/
Since json fields may change its order you should make your regex more tolerant for those changes:
val j = """{"resultCode":"SUCCESS","errorCode":null,"errorMessage":null,"profile":{"fullName":"TestFirstName TestMiddleName TestLastName","memberships":[{"name":"UA Gold Partner","number":"123-456-123-123","scanNumber":"123-456-123-123"}]}}"""
val scanNumberRegx = """\{.*"memberships":\[\{.*"scanNumber":"([^"]*)".*""".r
val scanNumberRegx(scanNumber) = j
scanNumber //String = 123-456-123-123
This will work even if the json fields will be in different order (but of course keep the structure)