my problem is what i need to write in the function expression in order to represent the prediction(label)?I mean how to call attributes in the function expression? this expression didn't work:
parent_path + "/" +"/new/" +prediction_label+ "/" + file_name
Use square brackets around the names of the attributes and be sure to use the exact names of the attributes. For reference, the Generate Attributes operator does a lot of the work for you. If you click on function descriptions you will see a small calculator-like icon to the right of function expressions. Once in this, you can select Special Attributes and you will see the exact names of the prediction attributes. Double clicking on the special attribute will cause it to be copied into the expression with square brackets if they are needed.
Related
I have an HTML array with data like so:
data-groups='["category_all", "data goes here"]'
I have a prop called "title" which contains the string I need to render in the "data goes here" area. I've tried using v-bind, but then I lose the array which I need to have in order for the original sort feature to work.
I google'd a few different ways to either escape or render quotes, and most refer to v-bind which again, won't work in this instance.
Any help would be appreciated :)
I was using Shuffle.js and for anyone else seeking an answer, it was in the documentation:
https://vestride.github.io/Shuffle/docs/getting-started
Alternatively, you can set the delimiter option to a comma (delimiter: ',') and the data-groups attribute will be split on that character.
Then changing the above line of code to:
:data-groups="item.category.title + ',all'"
works just fine :)
This is a question about semantics. What do I call the 'angular markup' here?
<h1>{{someScopeObject.someProperty}}</h1>
What's the proper way to refer to this and things like ng-model/ng-bind. Or do I go with specific names and say "the ng-model attribute / directive" and there isn't anything generic?
The double curly brackets are for data binding and what's inside the double curly brackets is an expression.
https://docs.angularjs.org/guide/expression
Disclaimer: I know that html and regex should not stand together, but this is an exceptional case.
I need to parse Google Search results and extract cache urls. I have this in the page:
<a href="/url?q=http://webcache.googleusercontent.com/search%3Fq%3Dcache:
gsNKb7ku3ewJ:somedata&ei=MyIIUtrZAcPX7AaVzIHwDg&ved=0CB8QIDAC&usg
=AFQjCNGcnWfdzQiTKwyAMmI-M-xzxII5Ag">Cached</a>
I tried simple stuff like: href=[\'"]?([^\'" >]+) but it is not what I need. I want to extract a single parameter (q) from the href. I need to get:
http://webcache.googleusercontent.com/search%3Fq%3Dcache:gsNKb7ku3ewJ:somedata
So everything between "url?q=" and first "&", when the contents contain word "webcache" in it.
If your language supports positive look-behinds:
(?<=q=).*?(?=[&"])
Otherwise match group \1 with this expression:
(?:q=)(.*?)(?=[&"])
Explanation:
.*? is the body of our expression. Just match everything, but don't be greedy!
(?<=q=) is a positive look-behind, which says "q=" should come before the match
(?=[&"]) is a positive look ahead, which says "either & or a quote should come after the match"
Because we make it not greedy with the ?, it'll stop at the first quote or ampersand. Otherwise it'd match all of the way to the closing quote.
Use a look behind before, and a look ahead at the end to assert the surrounding text, and include the keyword in the regex:
(?<=url\?q=)[^&]*webcache[^&]*(?=&)
Using [^&]* ensures that the keyword occurs before an & - within the target string.
I would like to highlight words matching a regular expression in a JTextPane.
I've seen various examples but they all where very complicated with complete syntax highlighting. I just want to highlight (or set in bold) a word/sentence, is there a simple way to do that?
If the overall underlying text of what is in the JTextPane is just a regular string and not HTML:
Get the underlying document from the JTextPane.
StyledDocument sdoc = textpane.getStyledDocument()
EDITED: changed to directly calling textPane.getStyledDocument, instead of casting the result of getDocument()
Get the text of the document.
String text = sdoc.getText(0, sdoc.getLength())
Use the Pattern and Matcher classes to find the locations that match the regular expression. I assume you already know how to do that.
For every location where a match is found, highlight the start to end of the matching substring with sdoc.setCharacterAttributes or use a highlighter (see JTextPane highlight text)
I found this useful regex code here while looking to parse HTML tag attributes:
(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?
It works great, but it's missing one key element that I need. Some attributes are event triggers that have inline Javascript code in them like this:
onclick="doSomething(this, 'foo', 'bar');return false;"
Or:
onclick='doSomething(this, "foo", "bar");return false;'
I can't figure out how to get the original expression to not count the quotes from the JS (single or double) while it's nested inside the set of quotes that contain the attribute's value.
I SHOULD add that this is not being used to parse an entire HTML document. It's used as an argument in an older "array to select menu" function that I've updated. One of the arguments is a tag that can append extra HTML attributes to the form element.
I've made an improved function and am deprecating the old... but in case somewhere in the code is a call to the old function, I need it to parse these into the new array format. Example:
// Old Function
function create_form_element($array, $type, $selected="", $append_att="") { ... }
// Old Call
create_form_element($array, SELECT, $selected_value, "onchange=\"something(this, '444');\"");
The new version takes an array of attr => value pairs to create extra tags.
create_select($array, $selected_value, array('style' => 'width:250px;', 'onchange' => "doSomething('foo', 'bar')"));
This is merely a backwards compatibility issue where all calls to the OLD function are routed to the new one, but the $append_att argument in the old function needs to be made into an array for the new one, hence my need to use regex to parse small HTML snippets. If there is a better, light-weight way to accomplish this, I'm open to suggestions.
The problem with your regular expression is that it tries to handle both single and double quotes at the same time. It doesn't support attribute values that contain the other quote. This regex will work better:
(\w+)=("[^<>"]*"|'[^<>']*'|\w+)
following regex will work as per HTML syntax specs available here
http://www.w3.org/TR/html-markup/syntax.html
regex patterns
// valid tag names
$tagname = '[0-9a-zA-Z]+';
// valid attribute names
$attr = "[^\s\\x00\"'>/=\pC]+";
// valid unquoted attribute values
$uqval = "[^\s\"'=><`]*";
// valid single-quoted attribute values
$sqval = "[^'\\x00\pC]*";
// valid double-quoted attribute values
$dqval = "[^\"\\x00\pC]*";
// valid attribute-value pairs
$attrval = "(?:\s+$attr\s*=\s*\"$dqval\")|(?:\s+$attr\s*=\s*'$sqval')|(?:\s+$attr\s*=\s*$uqval)|(?:\s+$attr)";
and the final regex query will be
// start tags + all attr formats
$patt[] = "<(?'starttags'$tagname)(?'tagattrs'($attrval)*)\s*(?'voidtags'[/]?)>";
// end tags
$patt[] = "</(?'endtags'$tagname)\s*>"; // end tag
// full regex pcre pattern
$patt = implode("|", $patt);
// search and match
preg_match_all("#$patt#imuUs",$data,$matches);
hope this helps.
Even better would be to use backreferences, in PHP the regular expression would be:
([a-zA-Z_:][-a-zA-Z0-9_:.]+)=(["'])(.*?)\\2
Where \\2 is a reference to (["'])
Also this regular expression will match attributes containing _, - and :, which are allowed according to W3C, however, this expression wont match attributes which values are not contained in quotes.