I need to get text inbetween single quotes(') will be in blue color what i need to change in my xml BeginBlock attribute using Regular expression?
This is my code :
<lexem BeginBlock='\'[.*]\'' Color="Blue" />
This is not working for me. Any one can tell where i did the mistake.
Help me !
You can try this regular expressions, but as Hamza said you would be better with a XML Parser
[^']\w+(?=')
(?>=').+(?=')
Try <lexem BeginBlock="'[.*]'" Color="Blue" />.
Or even shorter <lexem BeginBlock="'.*'" Color="Blue" />.
Related
I am trying to detect strings in other languages in my XML.
I thought I could use something like :
<xsl:analyze-string select="$mystring" regex="(\p{InGreek})" >
but I am unable to make this work.
Do you think this is possible in XSLT ? How would you do this ?
Thanks a lot.
Maria
(XSLT 2, Saxon-HE 9.8.0.8)
I think the right category name would be IsGreek so the regular expression would be \p{IsGreek}, however as the regex attribute of xsl:analyze-string allows attribute value templates you either need to put the expression into a string variable <xsl:param name="pattern" as="xs:string">\p{IsGreek}</xsl:param>you reference as regex="{$pattern}" or you need to duplicate the curly braces, as in regex="\p{{IsGreek}}".
I have the following XML code:
<quantity1 value="foo" name="bar">
<subquantity duration="2">
<parameter unit="meters" />
</subquantity>
</quantity1>
I want to export all names for further analysis in another document, but only if they have a certain subvalue. For example, how can I use regex to find all names based on if unit="meters"?
Bonus points if you can instruct how to do this in Notepad++. Open to other suggestions/SO posts as well.
Regular expressions are wrong for parsing XML.
Use XPath in XSLT or a scripting language or xmlstarlet instead.
Examples:
//quantity1[subquantity/parameter/#unit="meters"]/#name
//*[*/*/#unit="meters"]/#name
//*[.//#unit="meters"]/#name
Response text from sampler is :
<input type="hidden" name="pid" value="PID_1498281212971253461">
The basic reg ex extractor mentioned for most of the correlations is (.+?). I have read the basics of the reg ex by googling and trying to understand reg ex better Base on the understanding, I tried Reg Ex (2nd Reg Ex) which I am not getting any matches.
Extractor1: RegEx1
Extractor2:RegEx2
Pls. help me in understanding. Appreciate your help.
This is my first post in any channel, pls ignore any comm errors.
You're almost there, your regular expression is basically missing a repetition meta character to wit +. In its current state it will match only something like <input type="hidden" name="pid" value="PD_1">
So you need to add + sign to the end of each character classes groups and your regular expression should start working as expected
References:
JMeter: Regular Expresions
Perl 5 Regex Cheat sheet
When it comes to parsing HTML responses using regular expressions is not the best option, you might want to consider using CSS/JQUery Extractor instead
You could use the XPath Extractor instead, will be simpler, here is the XPath to use
//*[#name='pid']/#value
Please make sure, you check the options, Use Tidy and Quiet in the XPath Extractor
I have massive html code, with loooads of images, problem is, every single image has a different path, example:
<img src="../media/2010/01/something.jpg" />
<img src="../media/logo.png" />
What I wanted to do with regular expressions is, to find every image path and replace it with:
<img src="../img/FILENAME.EXTENSION" />
I know that it's definately possible with regular expressions ... but it's just not my cup of tea, could any1 help me please?
Cheers, Mart
This might not be the best solution but it might work:
(<img.*?src=")([^"]*?(\/[^/]*\.[^"]+))
and then you use capture group 1 and 3 to create the new string (depending on flavor):
$1../img$3
You can see it in action here: http://regexr.com?2v8ir
If you want to parse html, its much better if you use an html parser instead of regex. There are quite alot of them and they do a very good work.
Html Agility Pack is a good one
Try this link
Using this regex <img src="[\w/\.]+"(\s|)/> and replacing with <img src="../img/FILENAME.EXTENSION" />
I have a string like this:
This <span class="highlight">is</span> a very "nice" day!
What should my RegEx-pattern in VB look like, to find the quotes within the tag? I want to replace it with something...
This <span class=^highlight^>is</span> a very "nice" day!
Something like <(")[^>]+> doesn't work :(
Thanks
It depends on your regex flavor, but this works for most of them:
"(?=[^<]*>)
EDIT: For anyone curious how this works. This translates into English as "Find a quote that is followed by a > before the next <".
Regexes are fundamentally bad at parsing HTML (see Can you provide some examples of why it is hard to parse XML and HTML with a regex? for why). What you need is an HTML parser. See Can you provide an example of parsing HTML with your favorite parser? for examples using a variety of parsers.
If you are using VB.net you should be able to use HTMLAgilityPack.
Try this: <span class="([^"]+?)?">
This should get your the first attribute value in a tag:
<[^">]+"(?<value>[^"]*)"[^>]*>
If your intention is to replace ALL quotation marks within tags, you could use the following regular expression:
(<[^>"]*)(")([^>]*>)
That will isolate the substrings before and after your quotation mark. Note that this does not attempt to match opening and closing quotation marks. It simply matches a quotation mark within a tag.