Parsing in a MediaWiki DPL Regular Expression - regex

I'm tring to use the {{PAGENAME}} magic word in a regular expression to include an article based on the value of a parameter passed to a template. When I use the following statement with the article name hard-coded it correctly selects the articles I want:
includematch = /reportType\s*=\s*AccountReport/s
However, when I transclude the DPL into the AccountReport article, the following doesn't work:
includematch = /reportType\s*=\s*{{PAGENAME}}/s
Does anyone know what I'm doing wrong? Is {{PAGENAME}} being parsed before being used in the regular expression or is it trying to match the literal string?

I was using the DPL tag <dpl> but it wasn't parsing {{PAGENAME}} before applying the regular expression. When I changed it to use the parser function {{#dpl: then {{PAGENAME}} was evaluated and used within the regular expression as I required.

The way the dpl code is read makes it impossible for it to read the magic word. Use the dpl extension instead:
{{#dpl|code goes here}}

Related

jMeter Regular Expression Extractor with use of variable in regexp

I use jMeter 5.5-Snapshot 3a74a92. I need to use result of previous Regular Expression Extractor stored in variable in next Regular Expression Extractor when both Regular Expression Extractors are under same HTTP Request.
The example of fixed regexp that matches the result is:
<input type=\\"hidden\\" id=\\"def_SomeString\\" value=\\"(.*?)\\"/>
but 'SomeString' is something that is matched by previous Regular Expression Extractor and I have to use variable here. After several tries and analyzing debug output (that can be enabled by putting focus on Regular Expression Extractor then About->Enable Debug, do not forget to disable it later) I found that below regexp properly interprets variable and substitutes it:
<input type=\\\\"hidden\\\\" id=\\\\"def_${myVar}\\\\" value=\\\\"(.*?)\\\\"/>
Why in second expression with variable used all backslashes must be extra escaped in such weird way to match? Looks like using variable requires to use '\\\\"' to match '\"' which is unclear for me. Where in the documentation description of such usage can be found? I can't see anything about it there.
I don't think you need to have these extra escape backslashes in the 2nd regular expression.
I also don't think that using regular expressions for parsing HTML is a good idea, consider using CSS Selector Extractor instead.

How to parameterize a regular expression in jmeter

I have a variable
announcementName= test
I am trying to use regEx Extractor to match an expression in jmeter.
I am able to match data with the below expression.
{"id":(.*?),"announcementName":"test",
However I am unable to pass test as a variable to the same expression
{"id":(.*?),"announcementName":"${announcementName}",
I am unable to match anything with the above regEx matching.
Can someone please let me know on how to pass parameters to RegEx Extractor in Jmeter.
As per my experience, if you try this approach in listener to verify whether correlation is working or not than obviously it's not going to work.
But if you are passing this directly in reg ex extractor and trigger the script then it should work provided the variable does not contain any special character like (.,?) etc. (As you mentioned test as value so seems you took an example to display here but actual value is something else, so please check actual value once again to confirm it's a simple string without any special characters)
You can check with __V() function.
i.e.
{"id":(.*?),"announcementName":"${__V(${announcementName})}",

Regular expression to check path of url as well as specific parameters

I have url's like the following:
/home/lead/statusupdate.php?callback=jQuery211010657244874164462_1455536082020&ref=e13ec8e3-99a8-411c-be50-7e57991d7acb&status=5&_=1455536082021
I would like a regular expression to use in my Google analytic goal that checks to see that the request uri is /home/lead/statusupdate.php and has ref and status parameter present regardless of what order these parameters are passed and regardless of if there are extra parameters because I really just care about the 2. I have looked at these examples
How to say in RegExp "contain this too"? and Regular Expressions: Is there an AND operator? but I can't seem to adapt the examples given there to work.
Im using this online tool to test http://www.regexr.com/ (perhaps the tool is the buggy one? I'l try in javascript in the mean time)
You can try:
\/home\/lead\/statusupdate\.php\?(ref=|.*(&ref=)).*(&status=)
if the order does not matter, then add the oppostite
\/home\/lead\/statusupdate\.php\?(status=|.*(&status=)).*(&ref=)
all put together
\/home\/lead\/statusupdate\.php\?(((ref=|.*(&ref=)).*(&status=))|((status=|.*(&status=)).*(&ref=)))
try:
(/home/lead/statusupdate.php?A)|(/home/lead/statusupdate.php?B)|(/home/lead/statusupdate.php?C)|(/home/lead/statusupdate.php?D)|(/home/lead/statusupdate.php?E)|(/home/lead/statusupdate.php?F)
Note that here A,B,C,D,E,F are notations for six different permutations for 'callback' string, 'ref' string, 'status' string and '_' string.
Not really elegant but this works:
\/home\/lead\/statusupdate\.php(.*(ref|status)){2}
Looks for /home/lad/statusupdate.php followed by 2x any character followed by ref or status. Admittedly this would be a match for an url with 2x ref or status though.
Demo

How to write regular expressions for JMeter?

As I am new in using jmeter I'm stuck to write regular expression for this expression:
/catalog/search_display?category_id=9">Parts</a>
Can somebody help me out.
/catalog/search_display\?category_id=9">Parts</a>
Is that what you need? The question mark needs to be escaped, I don't see anything else noteworthy about it. The JMeter regexes are not enclosed in // and thus the slash is not a special character.
What do you want to extract? I assume that it is 9 (category_id). In that case regular expression extractor configuration should look like:
Reference Name: anything meaningful, i.e. id
Regular Expression: <a href="/catalog/search_display\?category_id=(.+?)"
Template: $1$
Refer extracted value as ${id} where required.
Mention that question mark needs to be escaped by a back slash as it is reserved character in regular expressions.
See Regular Expressions chapter of JMeter's User Manual for Perl5-style regex syntax and examples.
Also be aware that it isn't very recommended to parse HTML using regular expressions and it might be better to use the following post processors instead:
CSS/JQuery Extractor
XPath Extractor

Using - replace and pattern matching with XML tags Powershell

I am trying to replace the contents of a string which contains xml tags as follows
I want to replace the entirety of the below statement, where ABCDEF could be any random value
<originalFileName>ABCDEF</originalFileName>
How would I do this?
Solution
You can try this for your purpose:
(<originalFileName>[\w]*</originalFileName>)
Not recommended
However, note that it is not recommended.
Regular expressions are a tool that is insufficient to understand the constructs employed by XML/HTML/XHTML. XML/HTML/XHTML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down XML/HTML/XHTML into its meaningful parts. Even enhanced irregular regular expressions as used by Perl are not up to the task of parsing XML/HTML/XHTML.XML/HTML/XHTML is a language of sufficient complexity that it cannot be parsed by regular expressions.
Further details : RegEx match open tags except XHTML self-contained tags
This could help you:
EDITED (this new one will also accept non-characters between your tags and I have scaped the / symbol which can give some errors if not):
(<originalFileName>.*<\/originalFileName>)
Check it here.