w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Discrete distribution of numbers in binary?
The basic reason why your reasoning is wrong is that adding 0.9 is not an invertable operation. However you have it backwards. There are more floating point numbers between 0.0 and 0.1 than between 0.9 and 1.0. As for how to make an unbiased floating point RNG, you should initially generate numbers in the range [1.0,2.0) then translate and scale the result accordingly. This works because the interval [1.0,2.0) has uniform precision across the entire range (the exponent is the same for all numbers in this range). If you're working with IEEE single precision, which has the form: s eeeeeeee mmmmmmmmmmmmmmmmmmmmmmm Just fix the sign and exponent bits, and use a uniform random PRNG for integers to fill the mantissa bits. The same would apply to double.

Categories : C

jQuery Mobile Slider Steps not behaving when numbers are large
If i'm not mistaken, you can't override it except if you're willing to change the source code of jQm. The line that are the source of that behavior are in the function refresh. More precisely the following block: if ( typeof val === "object" ) { data = val; // a slight tolerance helped get to the ends of the slider tol = 8; left = this.slider.offset().left; width = this.slider.width(); pxStep = width/((max-min)/step); if ( !this.dragging || data.pageX < left - tol || data.pageX > left + width + tol ) { return; } if ( pxStep > 1 ) { percent = ( ( data.pageX - left ) / width ) * 100; } else { percent = Math.round( ( ( data.pageX - left ) / width ) * 100 ); } } In the case of an interraction w

Categories : Javascript

C - Printing random numbers from interval
... and then print which ones they are If you need to print numbers in the same order as they appear in polje array: #include <time.h> #include <stdlib.h> #include <stdio.h> int main () { int i; int br = 0, brr = 0, brrr = 0, br1 = 0; int polje[50]; srand(time(NULL)); for(i = 0; i < 50; i++) { polje[i] = rand() % 30 + 1; printf("%d ", polje[i]); } printf(" "); for(i = 0; i < 50; i++) { if(polje[i] >= 1 && polje[i] <= 10) br++; } printf("Brojevi od 1 do 10 pojavljuju se %d puta a to su ", br); // changed from here: for(i = 0; i < 50; i++) { if(polje[i] >= 1 && polje[i] <= 10) printf( "%d ", polje[i] ); } return 0; }

Categories : C

regex match string of exactly 6 numbers in text that has telephone numbers as well
It's a bit difficult to review the regex without the sample input but couple of observations: [0-9] can be replaced with d (since, you're already using it at the end) [D] is exactly the same as D. It's a character class itself and unless you have some more characters to include it'ss fine without being enclosed in []. (?:,) should simply be , because you neither want to capture it nor it has any quantifiers. ,[W_] Here it seems you want to use the character class but the would escape the first [. If you actually need a literal there; you need to escape it as \ since it's a special character.

Categories : PHP

Generate an array of numbers from an interval and keeping a minimum distance of units between them
Rather than try to generate perfectly separate numbers, why don't you just generate n number of random numbers until the criteria is met? Discard any that don't meet the criteria you have set. You can keep a running list of valid randoms you have generated and check against it. Look at http://stackoverflow.com/a/14568023/151234 for an idea on implementation.

Categories : Javascript

Convert integer numeric interval to regex
Why use regex in this situation? I would just do this: boolean isBetween = num > A && num < B; (Code written in Java) Far easier, a regex like what you're asking for could be huge and using it in this situation would be pointless and inefficient. Good Luck. If you truly insist on using RegEx for this task, see this website, run the regex with verbose mode on and it will explain to you how the author's RegEx works.

Categories : Regex

PHP Design Pattern Advice - many dependant steps that rely on results from previous steps
How you do this will depend upon whether or not you need to stop at a failed point or whether you wish to cancel the whole lot if any part fails. For the former, it is simple - just test at each step and if any fails, generate an error report. The latter is a little harder and will depend upon the db you are using. For Mysql in INNODB mode, you can use transactions, turning off auto_commit before starting a series of transactions and committing at the end if successful or rolling back the transactions if not. If you provide a little more information about the db and access you wish to use, you may get more help. I use mysqli and mysql for my code and find this handy when creating users with information spread across multiple database tables.

Categories : PHP

Ho to obtain random parameters for jbehave steps right from another steps
Are you try for the below scenario ? Given ..... When..... Then..... When the account comes to active state generate myAccnumber Then print myAccnumber That is,The Business people need to access(or pass) the myAccnumber in forthcoming steps.Right? In such case, declare a static variable in your step definition(As you suggest)class and let all your step definition can share it.

Categories : Selenium

Limit cucumber steps or steps file to specified feature or tag
In my experience overly generic steps lead to an extremely difficult to maintain automation code base. Try to go for a balance here if possible, only you can judge where this balance lies. You don't want overly repetitive step defintions but you don't want a super generic nightmare to debug. It's possible to use a workaround to get to the list of tags but please please do not do this. It's gross, weird and not how cucumber is intended to be used. As a workaround in your step_definitions you can use an around step to get a list of tag names from the scenario - Around do |scenario, block| begin @tag_names = scenario.tags.collect { |tag| tag.name } block.call ensure $tags = nil end end Then in the step_definition body check if the tag you want to detect is included in

Categories : Ruby

Generating random numbers on open-open interval (0,1) efficiently
Since the probability of actually observing 0 probability is very small, and checking if a number is equal to 0 is least expensive (as compared to addition or multiplication), I would regenerate the random number repeatedly until it is not equal to 0.

Categories : C

Big numbers regex
You need to have a pattern that starts the search with a decimal place. At the moment you're only deleting the . not the numbers after it... So you could do '/.[d]+/' $text = "1201.21 12 .12 12.21"; $text = preg_replace('/.[d]+/', '' ,$text); The above code would result in $text = "1201 12 12"

Categories : PHP

C# RegEx for Numbers up to 100
You're using the @ sign on your string, so you shouldn't escape characters. All you need is string pattern = @"^([1-9][0-9]{0,1}(.[d]{1,2})?|100)$";

Categories : C#

Regex not getting all numbers
.* is greedy by default - changing that selector to .*? results in a non-greedy matcher: >>> re.findall('<span>([a-zA-Z]+)</span>(.*?)([0-9]+)',string) [('Name', '</p><div class="info"><span>', '100')]

Categories : Python

REGEX To get seven numbers in a row?
If your entire string is possibly just a seven-digit string, you can use the following expression. It matches exactly seven numbers, and doesn't allow for any other characters in the input (won't match against g1234567 or 1234567g): ^(d{7})$

Categories : Python

How to shift an interval when using the C++ Boost interval container library (ICL)?
The canonical way is to construct a new interval and assign it to your interval because boost::lcl::discrete_interval is immutable (apart from the assignment operator). So to shift an interval you have to create a new interval with the desired lower and upper bounds and assign it to the old interval. boost::icl::discrete_interval<int> interval; interval = boost::icl::discrete_interval<int>::closed(3, 4);

Categories : C++

Conditional subsetting by POSIXct interval and another field containing interval
A possible solution very much inspired by @thelatemail's and @Justin's previous, nice answers, but this accounts for time in the boolean expression for space (see my comments to this question). Using sapply, we 'loop' over each time of registration of Species A (time[SP == "A"]), and create a boolean matrix mm with one column per registration of A. Each row represents a test for space and time for each registration against a given registration of A. mm <- with(dat, sapply(time[SP == "A"], function(x) abs(AR - AR[SP == "A" & time == x]) <= 1 & abs(difftime(time, x, units = "mins")) <= 30)) # select rows from data where at least one column in mm is TRUE dat[rowSums(mm) > 0, ] # SP time AR # 3 A 2003-01-

Categories : R

regex/sed example to spot numbers
Use grep to extract stuff: grep -oE '^[0-9]+' o to get only the matched part instead of the whole line, E for the regex sed is intended to do replacing.

Categories : Regex

Receiving one set of numbers with regex
You can use capture groups by placing the part you want between parentheses and calling it back using match.Groups[1].Value: string msg = @"""id"":""456138988365628440_103920"",""user""657852231654"""; var reg = new Regex(@"""id"":""([0-9_]*)"",""user""", RegexOptions.IgnoreCase); var results = reg.Matches(msg); foreach (Match match in results) { Console.WriteLine(match.Groups[1].Value); } ideone demo.

Categories : C#

Using javascript and maybe regex to get numbers out text
With regex you can do this: $("#input-field").val( $(this).html().match(/d+/)[0] ); ...that is, select the first digit or digits in the string using /d+/, where .match() returns an array so you need to grab the first (and only) element in the array. Demo: http://jsfiddle.net/WnruN/ Or you can just use .split(): $("#input-field").val( $(this).html().split(" ")[1] ); That is, select the second "word" (in your case a number). Demo: http://jsfiddle.net/WnruN/1/ Note that if you make your regex global by adding the g flag - /d+/g - then .match() will return an array of all of the numbers in the input string: http://jsfiddle.net/WnruN/2/ (If you want to allow for numbers with commas like in your first example use /[d,]+/g: http://jsfiddle.net/WnruN/3/)

Categories : Javascript

Write a regex to get numbers between two delimiters
Huh, that's almost the one I supplied to your other question xD Change the (.*?) to ([0-9]+) if (preg_match_all("/(?<=First)([0-9]+)(?=Second)/s", $haystack, $result)) for ($i = 1; count($result) > $i; $i++) { print_r($result[$i]); } .*? will match any character (except newlines) and to match only numbers in between your delimiters "First" and "Second", you will need to change it to [0-9]. Then, I assume that there can't be nothing in between them, so we use a + instead of a *. I'm not sure why you used [^0-9] in the beginning. Usually [^0-9] means one character which is not a number, and putting it there doesn't really do something useful, at least in my opinion.

Categories : PHP

Regex removing extension and numbers
It's because of d+: "one or more digits". You need d*: "zero or more digits". Files extensions can also have digits (e.g. ".mp3"), so use [a-zA-Z0-9]. You should add the "end of the string" anchor ($), which makes the global flag (g) useless. All these together: /s*d*.[a-zA-Z0-9]+$/ :)

Categories : Javascript

Finding Fibonacci numbers using regex
(?x) .? | ( \2?+ (\1|^.) )* .. There are a lot of things going on here which may confuse. I will go through each of these things in order to explain why the algorithm works. The match is being done on a string with the length of the regex, not the actual number. The only real data in the string is its length. \The double backslashes are just because in Java string literals backslashes have to be backslashed so that it is clear you aren't escaping something else. I won't show them in any future code in this answer. (?x): This enables extended regex mode. In this mode whitespace that is not backslashed or within a character class is ignored, allowing the regular expression to be broken into more readable parts with embedded comments. [sarand.com]. .?: This will match 0 or 1 characte

Categories : Java

Regex for thousand separated numbers
You could use this pattern: ^d+|d{1,3}(?:.d{3})*$ This will match any simple sequence of digits without thousands separators, or any sequence with . separators between every 3 digits. If you also want to support a comma as a thousands separator, use this: ^d+|d{1,3}(?:[,.]d{3})*$ Of course, to use any of these in Java, you'll need to escape the characters: String pattern = "^\d+|\d{1,3}(?:\.\d{3})*$"; Update Given your updated specs, I'd recommend this pattern: ^(?:0|[1-9][0-9]{0,2}(?:.[0-9]{3})*)$ You can test it here: Regex Tester

Categories : Java

Regex phone numbers python
/I is not how you give modifiers for regex in python. And neither you do substitution like s///. You should use re.sub() for substitution, and give the modifier as re.I, as 2nd argument to re.compile: reg = re.compile(regexPattern, re.I) And then for a string s, the substitution would look like: re.sub(reg, replacement, s) As such, your regex looks weird to me. If you want to match 7 digits numbers, starting with 25 or 29, then you should use: r'(2[59][0-9]{5})' And for replacement, use "51". In all, for a string s, your code would look like: reg = re.compile(r'(2[59][0-9]{5})', re.I) new_s = re.sub(reg, "51", s)

Categories : Python

Regex for replacing numbers to characters
Use this: x = x.replaceAll("\d", "X"); you don't need +, with it you specify that "one or more" digits are going to be replaced with a single X

Categories : Java

How to parse numbers from a string using regex
The issue is your handling of the output array. String.split removes the delimiter and does not include it in the array. Your numbers will be in numbers[0] and numbers[1]. numbers[2] will throw an exception.

Categories : Java

is it prohibited to use transition interval same as redraw interval?
Yeah, there are issues with d3 transitions. When the interval and duration are both 1000, there is high chance for the redraw operations to occur before the prior transition() on that selection is finished. And that messes with the data binding, or something along those lines. I modified your code such that it continuously checks whether the previous redraw transition has finished before calling the next one. This is by no means "good javascript", but it does illustrate the issue, and some way around it. To understand what I added, just look for all occurrences of __readyForNext in the code. It should make sense.

Categories : D3 Js

Set and Clear Interval turns into multiple Interval
Add a wrStoppTimer() call at the beginning of wrStartTimer: var wrStartTimer = function() { wrStoppTimer(); wrTimer = setInterval(function() { wrChange(wrAutomaticDirection); }, wrTime) }; Also in the two click functions you have: wrStoppTimer(); wrStartTimer(); you can remove that wrStoppTimer() call since wrStartTimer() will call it for you now. One other thing: if you define functions the way you're doing with var name = function() { ... } you should put a semicolon after the closing } as in the updated code above.

Categories : Javascript

Aggregate values of 15 minute steps to values of hourly steps
When working with time series, I suggest you work with xts package for this, and for example hourly.apply: library(xts) dat.xts <- xts(Total_Solar_Gesamt$TotalSolar_MW, as.POSIXct(otal_Solar_Gesamt$Timedate)) hourly.apply(dat.xts,sum) More general you can use period.apply which is (lapply equivalent) , for example to aggregate your data each 2 hours you can do the following: ends <- endpoints(zoo.data,'hours',2) period.apply(dat.xts,ends ,sum)

Categories : R

iOS regex pattern not working to match numbers
Try this regex: ^(?<!.)d*(.d+)?$ I added a negative look-behind assertion that means that no dot is allowed before that numbers. That should fix your problem.

Categories : IOS

PHP regex find and replace in text and numbers
It's not pretty but I'm late for dinner! <? $text = 'Bla bla bla, random text, bla bla... Text,number1: 12.3456°, text,number2: 78.9012°. And more text...'; $lines = array(); foreach(explode(" ",$text) as $line){ $match = array(); preg_match_all('/d{0,3}.?d{0,20}°/', $line, $result, PREG_PATTERN_ORDER); for ($i = 0; $i < count($result[0]); $i++) { $match[] = $result[0][$i]; } if(count($match)>0){ $lines[] = 'GPS:'.str_replace('°','',implode(',',$match)); } $lines[] = $line; } echo implode('<br>',$lines); ?> Bla bla bla, random text, bla bla... GPS:12.3456,78.9012 Text,number1: 12.3456°, text,number2: 78.9012°. And more text...

Categories : PHP

Regex javascript allow only numbers, alphabets and underscore
Perhaps you want something like this: var input = "f%o@o"; var output = input.replace(/W/g, ''); // "foo" This will remove any non-word character (a word character is a letter, number, or underscore) from the input string.

Categories : Javascript

Regex to match either range or list of numbers
First, you should use anchors to make sure that the regex match encompasses the entire string and not just a substring: ^[0-9]+-[0-9]+$ Then, the comma is optional in your second regex. Try this instead: ^([0-9]+,)+[0-9]+$

Categories : Regex

How can I return the first set of numbers from PHP string? Regex or Preg_Replace?
You need a regex that finds "everything from the first digit up to something that is not a digit". In other words: (d+) Feed this into preg_match() as preg_match('(d+)', '18 Bespoke(Size:S Colour:106) '); and it will return the first number (18) in its entirety. If that is not what you are after, please explain more clearly.

Categories : PHP

Regex Javascript Numbers Comma Separated | > | >= <=
This will match numbers between 3000 and 1000000, inclusive, allowing an optional fractional part separated by a coma: /^([3-9][0-9]{3}(,[0-9]+)?|[1-9][0-9]{4,5}(,[0-9]+)?|1000000)$/ You can test it here. This will match numbers greater or equal to 5000, allowing an optional fractional part separated by a coma: /^([5-9][0-9]{3}|[1-9][0-9]{4,})(,[0-9]+)?$/ You can test it here.

Categories : Javascript

Using regex to define masks for numbers in Java
An example with Pattern could be this: package test; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; public class Main { // working Pattern private static final Pattern PATTERN = Pattern.compile("^((1[234579])|42)"); // Your Pattern won't work because although it takes in account the start of the // input, the OR within a character class does not exempt you to write round brackets // around sequential characters such as "12". // In fact here, the OR will be interpreted as the "|" character in the class, thus // allowing it as a start character. private static final Pattern NON_WORKING_PATTERN = Pattern.compile("^[12|13|14|15|17|19|42]"); private static final String STARTS_WITH_1_234 = "8472952424"; private s

Categories : Java

regex to match or ignore a set of two digit numbers
Something like "(?<=_)(?!(19|20|21|22|23|24).)[0-9]+(?=.)" One or more digits `[0-9]+` that aren't 19-24 `(?!19|20|21|22|23|24)` followed by a . following a _ `(?<=_)` and preceding a . `(?=.)` http://regexr.com?35rbm Or more compactly "(?<=_)(?!(19|2[0-4]).)[0-9]+(?=.)" where the 20-24 range has been compacted.

Categories : Python

php regex, extract phone numbers from string?
? in regex means {0,1} and you need exactly 1 occurence of '-' in your pattern preg_match_all('/[0-9]{3}s*-s*[0-9]{3}s*-s*[0-9]{4}/',$output,$matches); For more info http://www.php.net/manual/en/regexp.reference.repetition.php

Categories : PHP

Regex only grab part of string - numbers only with a max length
You were close modify = Regex.Replace(modify, "FEW([0-9]{3})", "few clouds at $1"); ^ marks the beginning of string and $ marks the end of string and so it wasn't able to match it because your target string is in middile and not the only the string $1 refers to the first capture group but there wasn't any in your case.. You could also do it this way modify.Substring(modify.IndexOf("FEW"),modify.IndexOf("FEW")+5);

Categories : C#

Find numbers at specific positions in a string with Regex
The problem is that your .* is greedy so it's gobbling up the ([1-9]?) that comes after it. If you use a non-greedy quantifier (.*?), you'll get the result you want: string str = "dddd - 2013-0Winter1 morning2"; Regex pattern = new Regex("^.* - ([0-9]{4}-).*?([1-9]?) .*?([1-9]?)$"); Match match = pattern.Match(str); for (int index = match.Groups.Count - 1; index > 0; index--) { str = str.Remove(match.Groups[index].Index, match.Groups[index].Length); } Console.WriteLine(str); // dddd - 0Winter morning Of course, this will produce the same result: string str = "dddd - 2013-0Winter1 morning2"; str = Regex.Replace(str, @"^(w*? [0-9]{4}-w*?)[1-9]? (w*?)[1-9]?$", "$1 $2"); Console.WriteLine(str); // dddd - 0Winter morning

Categories : C#



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