w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

How can I properly handle greedy and optional patterns in python regex
Perhaps you could target lesser characters instead of .* ^//network/path/folder/_.*?/[^/]*/([^/]*) http://regexr.com?356lh [^/]* means any number of occurences of any character but NOT A FORWARD SLASH. ^ is not flag.

Categories : Python

Parsing SQL statements with regex: Does adding the optional flag in a regex expression change how greedy or posessive modifiers are matched?
Parsing SQL with regex is not much different from parsing HTML with regex. In other words, it won't work. It is hopeless task, stop right now. Instead, use some SQL parser. For example, SQL::Statement::Structure for Perl or ANTLR for Java. Also, since you are creating your own database, it is worth taking a look at how other SQL implementations do it. I would recommend reading source code for PostgreSQL or MySQL and see how they implement advanced SQL parsing.

Categories : Java

Optional group following non-greedy group
Try with this regex: re.compile(r'^Pref(w+?)(?:Value(d+))?$') Note that [wd_] is same as w. You have to make Valued+ collectively as optional. For that you have to make them a group. But since you don't want to capture them, you can use a non-capturing group. Also, you can make the d+ part in it a capturing group, so that you can get that part. The issue with "Pref(w+)(?:Value(d+))?" is that, w+ will match everything till the end, and satisfy the regex, as Valued+ part is optional. So, everything will be captured in w+. So, you have to make it reluctant - w+?. Now, your desired output is in group 1 and group 2. For the 2nd case, group 2 will be null.

Categories : Python

Greedy "?" not acting greedy for spaces in ANTLR4
Your token stream currently can never contain a SPACE token because the TEXT token matches SPACE+ (among other things) and appears before the SPACE token in the grammar. Your control rule allows a SPACE token, but does not allow TEXT which is what it's actually seeing for that space character.

Categories : Ant

perl optional command line argument
The arguments to a subroutine are passed in an array. It looks like you already realise that as you're building up your arguments in @args. If your subroutine is just expecting a list of arguments of arguments, then there are some problems with your approach. Firstly, as you've realised, if you push an empty array onto an array, you will get no items added on to your @args array. And that's going to confuse your subroutine. It's simple enough to test this using Data::Dumper. #!/usr/bin/perl use strict; use warnings; use 5.010; use Data::Dumper; my @arguments = ('Arg1'); my @controller; my @member; my @args; push(@args, $arguments[0]); push(@args, @controller); push(@args, @member); say Dumper @args; The output looks like this: $ ./args $VAR1 = [ 'Arg1' ]; But

Categories : Perl

javascript object literal, combining values of objects within same literal
I'm a little unclear on the exact math you're trying to achieve, but I think I can help with the looping. You don't need two loops, just one to iterate through the array of data objects. Then, build yourself a new array of your new objects. Like: var newData = []; for (var i=0; i<data.length; i++) { var currentDataObject = data[i]; // don't really need this but just to make it clear newData.push({ repId: currentDataObject.repId, profit: your math here, expense: your math }); } For the record though, if you did need to iterate through the properties of an object, you'd need to use the "for (var key in data)" syntax.

Categories : Javascript

JavaScript string literal in object literal syntax error
You have an unclosed string literal. JavaScript strings are not multi line by default. var modalcontent = { description1 : '<div id = "description"><div class = "tbc"> '+ '<label class = "tbc" for = "tbc">Description</label>'+ '</div>'+ '<div class = "tbc">'+ '<input type = "text" class = "tbc" name = "description" id = "tbc" placeholder = "Enter description">'+ '</div>'+ '</div>'+ '<!--end description div-->' } (fiddle) Alternatively, you can create multi line string by using the character, those only work in newer implementations. See this related question or the language specification. Note: It's usually not the best idea to store HTML in strings, it makes it harder to debug and work with. You can usually

Categories : Javascript

Perl Regex: Matching text with optional multi-line
You can try with this pattern: (?>$obj_files_no_ext-objss*:=|G)s*K(?>[^s.]++|.(?!o(?:s|$)))++.o pattern details: (?> # open an atomic group $obj_files_no_ext # radical -objss*:= | # OR G # contiguous match ) # close the atomic group s*K # optional spaces and reset all the match (?> # open an atomic group (filename possible characters) [^s.]++ # all that is not a white character or a dot (1+ times) | # OR .(?!o(?:s|$)) # a dot not followed by "o", a space or the string end )++ # repeat the atomic group one or more times .o example: #!/usr/bin/perl use strict; use warn

Categories : Regex

How to append regex literal with string literal in javascript
Don't use a literal. Use the RegExp constructor : var reg = new RegExp("(\d+\s" + query + ")");

Categories : Javascript

How do I make command line arguments with a hyphen (-) show up as non-optional in python v2.7?
Please use the required keyword when adding it to the argparse: http://docs.python.org/2/library/argparse.html#sub-commands parser.add_argument("-b", help='Build number, e.g., 1234', required=True)

Categories : Python

Is a character literal ('A') exactly equivalent to a hex literal (0x41)
Is there any situation in which changing 'A' to 0x41 could change the behaviour of my program? Yes, in EBCDIC character set 'A' value is not 0x41 but 0xC1. C does not require ASCII character set. (C99, 5.2.1p1) "The values of the members of the execution character set are implementation-defined."

Categories : C

Making semicolons optional for some rules while keeping the trailing semicolon optional?
Move the SEMICOLON symbol to expr (semantically it belongs to that anyway). expr: A SEMICOLON? | (B | C) {LA(1) != EOF}? SEMICOLON ; exprs: expr+ ; Update: changed the B and C branch to use a lookahead to decide.

Categories : Ant

Shell: Is it possible to parse optional parameters after non-optional ones?
Traditionally in unix, optional parameters have come first, at least for most shell utilities, and that is the Posix recommendation for writing shell utilities. The bash builtin getopts is designed for this use case as well; unless you yourself reorder the command line parameters, getopts will only work with option parameters coming first. However, most gnu utilities use the gnu getopt or getopt_long C APIs, both of which by default allow optional parameters to come anywhere in the command line. And even with Posix shell utilities, there are some exceptions to the standard. In short: you should always be safe putting optional parameters first, but in some cases you can put them at the end utilies written using the bash getopts built-in practically always require optional parameters to

Categories : Bash

Entity Framework optional:optional relationship
It looks like you're trying to set up a 1:0..1 relationship from your AdditionalType objects (which I may have misinterpreted completely. N.B. I think you would have to hold a BaseTableId on your BaseTable for this to work (or define a primary key): If BaseTableId is the foreign key in this instance, I think this may be what you're after: modelBuilder.Entity<AdditionalType1>() .HasOptional(zmt => zmt.BaseTable) .WithMany() .HasForeignKey(a => a.BaseTableId); Which is what I've used previously, but can't admit to understanding it fully (the .WithMany() trips me up); it's a slight workaround listed in article from this answer: Entity Framework 0..1 to 0 relation) Apologies if I've missed the point entirely.

Categories : C#

Matching a string till a symbol and make it optional. Do not capture the matched optional string too
Looks to me like your regex should work, but it probably can be improved. Should the match always start at the beginning of the string? (That's a trick question; if you can't make that assumption, the question makes no sense at all.) Will there ever be more than one semicolon? If so, do you want the non-capturing part to extend only up to the first one, or to the last one? Should it always end at the end of the string, or do you only want to match up to the period? Can there ever be more than one period? This minimally changed regex seems to do what you want, and the added anchors will probably improve performance enough to meet your needs: ^(?:.*?;s*)?(.+)..*$ This one should be considerably faster; replacing .* with negated character classes ([^;]* and [^.]+) almost comple

Categories : Regex

why is this dot not greedy?
The .+ can match the entire string, but then the b that follows it would have nothing to match. Greedy matching means that it will match as much as possible while still making it possible for the pattern that comes after it to successfully match.

Categories : Javascript

Greedy Quantifiers
why doesn't it match the whole text? Because you stated it must start with proj1 Being greedy it should have match the rightmost "proj1.java" correct. and the returned match should have been the entire source before the right most match? no idea why you would think that, or why that would be useful. You can just do .*proj1.* if that is what you want.

Categories : Java

XmlReader is too greedy
Found the answer in this question. The XmlReader has to be set to read a fragment only, not a document. using (var xmlReader = XmlReader.Create(_tcpReader, new XmlReaderSettings {ConformanceLevel = ConformanceLevel.Fragment})) { xmlReader.MoveToContent(); var xmlElement = (XElement) XNode.ReadFrom(xmlReader); // works! } Note that XElement.Load dies: reader is expected to be EOF after this operation.

Categories : C#

sed alternative to non-greedy searching
I don't believe in this case it matters that sed does not support non-greedy regex, a non-inclusive range-replacement such as the below should suffice. I ran a test with GNU sed, see results below sed '/^VAR.*="/,/^"/ {/"/! s/^/A/}' testfile.txt VARIABLE=" Atext1 Atext2 Atext3 " test data test p VARIABLE=" Atext1 Atext2 Atext3 " test data EDIT: Or as Potong points out, this can be reduced to the more idiomatic form sed '/^VAR.*="/,/^"/ {//! s/^/A/}' testfile.txt

Categories : Regex

Optimization with a greedy algorithm
I am interpreting your question as "the set of all optimal solutions must always contain the first choice" otherwise it does not make sense for a solution to contain another solution. Naturally, the answer is trivially yes. If a greedy algorithm solves the problem, it produces an optimal solution, which by definition is in the set of optimal solutions. Perhaps you meant "if a greedy algorithm sometimes produces an optimal solution, ..." in that case again the answer is trivial. If you meant that "if a greedy algorithm sometimes produces an optimal solution, is it true that all guaranteed optimal algorithms will produce that solution too?" the answer depends upon whether the problem has a unique optimal solution or multiple ones. If a problem has multiple optimal solutions, the answer i

Categories : Algorithm

Greedy not capturing the first event
greedy effects parent-child relationships, not sibling relationships. See This Fiddle For Example basically, greedy:true stops events from bubbling to parent elements. In your example fiddle, the 2 elements are siblings so the function is fired twice. In my example fiddle, box 2 is a child of box 1 so only box 2 fires the function.

Categories : Jquery

What should I use the Non-greedy match in this case
Regex might be complicating this problem rather than simplifying it. A simple way to get an eighth item from a | delimited string is using split(): a = '|here|is|some|data|separated|by|bars|hooray!|' print a.split('|')[8] RETURNS hooray! Using regex, one way to get it would be: import re a = '|here|is|some|data|separated|by|bars|hooray!|' pattern = re.compile(r'([^|]+)') match = pattern.findall(a) print match[7] RETURNS hooray!

Categories : Python

ANTLRv4: non-greedy rules
ANTLR 4 lexers normally operate with longest-match-wins behavior, without any regard for the order in which alternatives appear in the grammar. If two lexer rules match the same longest input sequence, only then is the relative order of those rules compared to determine how the token type is assigned. The behavior within a rule changes as soon as the lexer reaches a non-greedy optional or closure. From that moment forward to the end of the rule, all alternatives within that rule will be treated as ordered, and the path with the lowest alternative wins. This seemingly strange behavior is actually responsible for the non-greedy handling due to the way we order alternatives in the underlying ATN representation. When the lexer is in this mode and reaches the block (ESC|.), the ordering constr

Categories : Ant

MVC5 Bundler being too greedy?
If you run with debug=true, by default the bundle's contents will be enumerated as individual links and you can see approximately what its trying to include. It will differ slightly as it will choose .min.js over plain .js.

Categories : Jquery

How can I do a non greedy regex query in notepad++?
Use a reluctant (aka non-greedy) expression: \cite[(.*?)] The addition of the question mark changes the .* from greedy (the default) to reluctant (non-greedy), which means it will consume as little as possible to find a match, which means it won't skip over multiple search terms such that it matches using the open square bracket if the first cite and the closing square bracket of the last cite. See a live demo of this regex working with the sample in the question.

Categories : Regex

how to make this regular expression greedy
Try something like this: *{((?!}*).)*}* Or in Java form: \*\{((?!\}\*).)*\}\* It uses a negative lookahead to distinguish the }* closing tag from } alone. That's the ((?!}*).)* part. Edit: Here's a (Java) version that allows newlines. You can also use Pattern.DOTALL to make . include newlines, so the above patterns will work. \*\{((?!\}\*)[\s\S])*\}\* Note that this will not be recursive. You can't have something like *{ foo *{ bar }* }* and have the whole thing treated as a comment. That would make this a context-free grammar, and trying to parse CFGs is among the most famous no-nos with regex.

Categories : Regex

How to make this json regex greedy
.*? is a non-greedy (or lazy) quantifier. To make it greedy just remove the ?: "body": { "content": "<div class=(?:"|')content(?:"|') [^>](.*)</div>\;content:\1", } Of course, as has been said many times before, you shouldn't use regular expressions to parse html. To use the global mode, simply specify it when you're creating your RegExp, either like this: "body": { "content": /<div class=(?:"|')content(?:"|') [^>](.*)</div>\;content:\1/g, } Or like this: "body": { "content": new RegExp("<div class=(?:"|')content(?:"|') [^>](.*)</div>\;content:\1", "g"), } Of course at this point, it's no longer pure Json. Really, I'd recommend specifying the flags elsewhere. For example, in whatever code you have which actually does the html processin

Categories : Javascript

How to make this javascript regex greedy?
(=1)* will match =1=1=1=1=1=1=1=1 If you're looking to match all digits after the = then use abcde=(d+) This will place all the digits into capture group 1.

Categories : Javascript

Autofac not finding the most greedy constructor
Problem was that my greedy -was- getting called .. but if u looked at the greedy-ctor, you'll see that i'm doing : this(). very lame newbie error. So it was calling the greedy ctor, but before it goes into scope, it has to bubble up to the other parameterless ctor. And I kept thinking it was skipping the greedy and just hitting the parameterless. Error Between User And Keyboard.

Categories : C#

Getting non-greedy sequence as a string with ANTLR
if you want to do it in this way, you can do it like this: grammar Sequence; parse : line+; line : '{TEXT="' a=sequence '"}' {System.out.println(((LineContext)_localctx).a.getText());}; sequence : .+?; ANY:.; But there also other mechanisms in ANTLR4 like listeners and visitors.

Categories : Java

Greedy Algorithm - Depreciating Cost
Suppose there are N items with individual Ri. Compute the N x N matrix where Cij = Power(Ri,j). The problem now boils down to Assignment problem with N objects to be placed in N positions and each having corresponding profits associated. Maximize the total profit using any algorithm like the Hungarian Algorithm.

Categories : Algorithm

Non-greedy regex match when searching from end
Try this: http://[A-Za-z0-9_-]+.png It wont get the first http:// because it has more than [A-Za-z0-9_-]+ between it and .png Could also use this if you are worried about other characters in the URL: http://[^:]+?.png

Categories : Objective C

Greedy global RegExp matching in JS
use .match instead of .exec : 'fofoofooofoooo'.match(RegExp('f(o+)', 'g')) // ["fo", "foo", "fooo", "foooo"] Used to retrieve the matches when matching a string against a regular expression.

Categories : Javascript

Perl regex becoming greedy when used (.*?) with anchors
Do you really want to match > characters? I bet you don't... So don't use .* and that will solve your greediness problem. Use [^>]* instead. It's guaranteed to stop as soon as it hits the first > (even without tacking on a ?) because > doesn't match.

Categories : Regex

Regex Getting too Greedy (Java/android)
For this: Then $1 matches test and $2 matches <lots of stuff in this subtag /></myset><myset setName="test2"><more stuff in here /> It sounds like you were using the following expression: <myset setName="(.+?)">(.*)</myset> Example: http://www.rubular.com/r/516CWASjAF Your expression <myset setName="(.+?)">(.*?)</myset> works for me on your sample string but I do recommend changing your expression to following so that if the quoted text is empty, then at least the engine won't leave that area of the string: <myset setName="([^"]*)">(.*?)</myset>

Categories : Java

perl non-greedy regex case matching too much
You aren't using non-greedy, you have greediness within an optional capture group as the question mark is right after the group's end parenthesis: Change: description="(.*)?" to: description="(.*?)" and you should have your expected results.

Categories : Regex

Simple greedy algorithm. Infinite loop
You need a case when change is between 0.01 and 0.0, maybe avoid the last if()? else if(change >= 0.05){ change -= 0.05; } else /*if(change >= 0.01)*/ { change -= 0.01; }

Categories : C++

Jquery droppable - Greedy not working as expected
Here's the thing. jQuery UI prevents a ancestor droppables from receiving drop events when a descendent droppable is configured with {greedy: true}. It does not prevent sibling or cousin droppables from receiving drop events in cases where one overlaps the other. This is a design decision by jQuery UI. They do not intend to fix it.

Categories : Javascript

python RE: Non greedy matches, repitition and grouping
To do this with a regex, you must use a lookahead test: r"start_of_line:.*?(?=start_of_line|$)" otherwhise, since you use a lazy quantifier ( *? ), you will obtain the shortest match possible, i.e. nothing after start_of_line: Another way: r"start_of_line:(?:[^ ]+| (?!start_of_line:))*" Here i use a character class containing all but a newline ( ) repeated one or more times. When the regex engine find a newline it tests if start_of_line: doesn't follow. I repeat the group zero or more times. This pattern is more efficient than the first because the lookahead is performed only when a newline is encounter (vs on each characters)

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.