w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Regular expression match a-alphanumeric&b-digits&c-digits
you can use this pattern : ^(?i)a-([0-9a-z]++)&b-([0-9]++)&c-([0-9]++)$ In the case what you try to match is not the whole string, just remove the anchors: (?i)a-([0-9a-z]++)&b-([0-9]++)&c-([0-9]++) explanations: (?i) make the pattern case-insensitive [0-9]++ digit one or more times (possessive) [0-9a-z]++ the same with letters ^ anchor for the string start $ anchor for the string end Parenthesis in the two patterns are capture groups (to catch what you want)

Categories : Java

using quotient and remainder operators to extract and print each digit
You asked the same question a few minutes ago. We told you like This is not a good way to ask a question in here but anyway.. int i = 7658; Console.WriteLine(i % 10); //Last digit. i = i / 10; Console.WriteLine(i % 10); //Third digit. i = i / 10; Console.WriteLine(i % 10); //Second gidit. i = i / 10; Console.WriteLine(i % 10); //First digit. Logic is here; 7658 % 10 = 8 (Gives the last digit) Take a look % Operator Make integer division with 10 Continue to step 1 while number is bigger than 10. As a visual, I steal some part of SWeko's answer; 7658 % 10 = 8 765 % 10 = 5 76 % 10 = 6 7 % 10 = 7

Categories : C#

How to extract a number into digits using R?
Use substring to extract character at each index and then convert it back to integer: x <- 4321 as.integer(substring(x, seq(nchar(x)), seq(nchar(x)))) [1] 4 3 2 1

Categories : R

How to extract occurrence of str + digits from string in C
Since digits are not consecutive, and it contains '_' too, you need a way to scan them and skip scanning if its neither a digit nor a '_' Something like this : char res[15]={''}; if (first != NULL) { start = second = first; while(*second != '') { if (isdigit(*second)) { start =second; // Store the start of the "thing" //Start another loop to check for the "thing" while(*second != '') if(*second=='_' || isdigit(*second) ) second++; else break; //Something else, exit now break; } second++; start++; } } strncpy ( res, start, second-start ); //Store Result res[second-start] = ''; printf("%s %s ",find,res); See HERE

Categories : C

Extract two lines of digits from a String
Uri uri=Uri.parse(yourString); String result=uri.getQueryParameter("q"); Then split your result with ,,which gives you a array of strings (contains your numbers as strings).

Categories : Java

Extract numbers buried in excel by count of digits
You will need to use a regular expression. You'll need to reference (Tool > Reference) the "Microsoft VBScript Regular Expressions 5.5" Try the following code, it should give you what you want, matching any sequence of 7 digits. You'll need to modify it if it's possible to have more than one sequence of 7 digits or a sequence of more than 7 digits Sub FindNumber() ' Reference: Microsoft VBScript Regular Expressions 5.5 Dim RegEx As Object ' VBScript_RegExp_55.regexp Dim MatchCol As MatchCollection Set RegEx = New RegExp With RegEx .Pattern = "(.*)([0-9]{7})(.*)" .IgnoreCase = True .Global = True End With For i = 1 To 3 Step 1 If RegEx.Test(ActiveSheet.Cells(i, 1).Value) Then Set MatchCol = RegEx.Execute(ActiveSheet.Cells(i, 1).Value) ActiveSheet.C

Categories : Excel

Python re.match only characters, digits and some punctuations
Use this to check all characters until the end of your string, otherwhise your pattern will only check the first character: re.match('^[A-Za-z0-9.,:;!?()]+$', str) Note that the character class doesn't contain spaces, newlines or tabs. You can add them like this: re.match('^[A-Za-z0-9.,:;!?()s]+$', str) If you want to allow void strings you can replace the + quantifier by *

Categories : Python

Match and replace digits with sed in specific lines
You cannot use sed like that. You need to use multiple sed replacements with -e switch like this: sed -i.bak -e '9s/[0-9][0-9]*('$' '')/11/' -e '13s/[0-9][0-9]*('$' '')/11/' -e '17s/[0-9][0-9]*('$' '')/11/' -e '21s/[0-9][0-9]*('$' '')/11/' file Update: Though awk doesn't support inline editing I believe using awk will be much cleaner for this task. Consider below awk command: awk 'NR ~ /^9|13|17|21$/{sub(/[0-9]+ $/, "1 ")}1' file > _temp && mv _temp file

Categories : Bash

multiline regex pattern that match 3 digits
So the entire file must look like this? Then try new Regex(@"A(?:d{3} ? )*z") Explanation: A # Start of string (?: # Match the following (non-capturing) group: d{3} # - three digits ? # - one CRLF or LF (linebreak) )* # any number of times (0 or more) z # until the very end of the string If the file might not end with a newline (not sure from your description), you can use new Regex(@"A(?:d{3} ?$ ?)*z", RegexOptions.Multiline) This initially makes newlines optional ( ? ?) but ensures that there is a line ending after every three-character bit by placing the end-of-line anchor $ between CR and LF, which is where (strangely) .NET thinks it should match.

Categories : Dotnet

Regular expression for Less or more than 9 digits Repeating digits for first 5 or all 9 digits and only number?
By your last comment, you need a regex to validate a string of maximum length 9 containing digits only: ^[0-9]{1,9}$ This will validate any string containing digits, with length at least 1 and not greater than 9. If you want to avoid strings such as 098 (leading zeroes), use this instead: ^[1-9][0-9]{0,8}$ EDIT: If I understand your question well now, you can use this regex: ^(?!([0-9])11-11)[0-9]{3}-[0-9]{2}-[0-9]{4}$ That is assuming that echosign can handle callbacks, if not, you can use this instead: ^(?!(?:111-11|222-22|333-33|444-44|555-55|666-66|777-77|888-88|999-99|000-00))[0-9]{3}-[0-9]{2}-[0-9]{4}$

Categories : Regex

ColdFusion Regex Match for Digits of Exact Length
The general way to exclude content from occurring before/after a match is to use negative lookbehind before the match and a negative lookahead afterwards. To do this for numeric digits would be: (?<!d)d{5}(?!d) (Where d is the shorthand for [0-9]) CF's regex supports lookaheads, but unfortunately not lookbehinds, so that wouldn't work directly in rematch - however that probably doesn't matter in this case because it's likely that you don't want, for example, abc12345 to match either - so what you more likely want is: d{5} Where  is a "word boundary" - roughly, it checks for a change between a "word character" and a non-word character (or visa versa) - so in this case the first  will check that there is NOT one of [a-zA-Z0-9_] before the first digit, and the second  will chec

Categories : Regex

extract file content from match pattern to another match pattern
With awk: awk '/> myoccupation/,/> mygrosssalary/' file With sed: sed -n '/> myoccupation/,/> mygrosssalary/p' file And you can use output redirection to create another file, with comand ... > newfile

Categories : Linux

Extract string from match
$markup = '<span class="Products-Name">Used Gibson USA</span> <span class="Products-Discription">Les Test Test Test Paul Custom 1986 <br />with Factory Kahler </span>'; $markup = preg_replace('~<br\s*/?>~si', ' ', $markup); // replace <br> with space $markup = preg_replace('~\s+~', ' ', $markup); // compact consecutive spaces into a single space if(preg_match_all('~<span class="Products-(.+?)">(.*?)</span>~si', $markup, $matches)){ // trim the enite deep array array_walk_recursive($matches, function(&$match){ $match = trim($match); }); // this shows you how the $matches is structured list($raw_matches, $class_matches, $inner_matches) = $matches; // combine class names with span inner value

Categories : PHP

php xml xpath how to extract desired match
Your xpath is all right, but the XML is not valid, see http://www.xmlvalidation.com The & within your links will be parsed as start of a character entity --> error. solution: exclude the text within <sourceURL> from parsing with <![CDATA[...]]>: $x = <<<XML <imageList> <image available="true" height="100" width="100"> <sourceURL> <![CDATA[images/di/47/6b/77/454430384d6d324b413332544a695675313851-100x100-0-0.jpg?p=p2.7f19fe93a466ae45afab&a=1&c=1&l=7000610&r=1&pr=1&lks=43998&fks=35198]]> </sourceURL> </image> ... </imageList> XML; $xml = simplexml_load_string($x); $result = $xml->xpath("//image[@height='400']/sourceURL")[0]; echo $result; output: images/di/47/6b/77/45443038

Categories : PHP

extract match and different from 2 huge text files
Use sort and join. See bash example below that takes advantage of process substitution join -o 1.1 <(sort file1) <(sort file2) > file3 join -o 1.1 -v 1 <(sort file1) <(sort file2) > file4 join -o 2.1 -v 2 <(sort file1) <(sort file2) > file5

Categories : Linux

How to extract which combination of regex match from my pattern?
You can use matcher.group() method once you get Matcher out of that Pattern Matcher m = ANIMALS.matcher("The boy is good"); while(m.find()) { System.out.println(m.group()); }

Categories : Java

Regex to match MAC address and also extract it's values
If you want all the matches, you should avoid using {5}: mac_regx = re.compile(r'^([0-9A-F]{1,2}):([0-9A-F]{1,2}):([0-9A-F]{1,2}):([0-9A-F]{1,2}):([0-9A-F]{1,2}):([0-9A-F]{1,2})$', re.IGNORECASE) or, shorter, mac_regx = re.compile(r'^([0-9A-F]{1,2})' + ':([0-9A-F]{1,2})'*5 + '$', re.IGNORECASE) You could also make a list of 6 occurrences of a string '[0-9A-F]{1,2})' and join them with ':'.

Categories : Python

Extract all characters after a match - shell script
You were pretty close: grep -oP '(?<=w=)w+' file makes it. Explanation it looks for any word after word= and prints it. -o stands for "Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line". -P stands for "Interpret PATTERN as a Perl regular expression". (?<=w=)w+ means: match only w+ following word=. More info in [Regex tutorial - Lookahead][1] and in [this nice explanation by sudo_O][2]. Test $ cat file NAME=John Age=16 $ grep -oP '(?<=w=)w+' file John 16

Categories : Shell

Lua string.match to extract some values of a HTML
- is a special control character in Lua patterns. Since you want the literal - character, you need to escape it with the % character. So use %-.

Categories : Lua

Lucene.net - How do I extract small snippets of texts from each match?
In order to be able to access the text adjacent to the match, you will need to store TermVectors with position and offset information at indexing time, which you can then use to retrieve the surrounding words. See http://searchhub.org/2009/05/26/accessing-words-around-a-positional-match-in-lucene/ for a detailed explanation.

Categories : C#

How to Convert Persian Digits in variable to English Digits Using Culture?
You need to parse them first, using e.g. Int32.Parse() with the correct cultural specifier. Once you have it as a plain integer, it's simply a matter of calling ToString() on it, again with the correct cultural specifier. An alternative solution is to walk the string character by character and just replace any character that is a Persian digit with the corresponding (west) arabic numeral. Other characters can then be preserved as-is, if required. If the string really contains a number, you should go with the integer parsing method. If it is not just a number, but really a phone number, serial number etc, you might need to use the replacing algorithm instead.

Categories : C#

Computing float to 2 digits only (not formatting/rounding off 6 digits after decimal to 2)
There is nothing you can 'tell' math.h (in this regard); float does not have precision options. If you want less computational intensive calculations you must use other types or methods. You already mention the best candidate: fixed-point. But, for obscure reasons, you say that you can't use it. Other idea is to scale up your calculations by for example a factor 10,000, and keep everything as int (or longer). Then, only scale down to float when needed. But of course, it depends on your problem if you can do this.

Categories : C

How to extract lines numbers that match a regular expression in a text file
This should solve your problem, presuming you have correct regex in variable 'phrase' import re # open the files outputLineNumbers = open('OutputLineNumbers', 'w') inputFile = open('Corpus.txt','r') # read the corpus first corpusLines = inputFile.readlines() # loop through each line in corpus for line_i in range(len(corpusLines)): line = corpusLines[line_i] # check if we have a regex match with "phrase" variable # if so, write it the output file if re.match( phrase, line ): outputLineNumbers.write( str(line_i+1) + " " ) # close the file handles outputLineNumbers.close() inputFile.close()

Categories : Python

how to extract a record in a text on string match in a file using windows bash
try this line: awk -F: '{a[++i]=$0;if(i==3)f=$2}i==4{for(x=1;x<=i;x++)print a[x]>f".txt";i=0}' file this line will name the output file with the author's name. And if the name has space, you have to quote it. If you need a numbered text file, it is also easy, just create an array during reading lines. something like: f['John']=1 f['Tom']=2 f['Jerry']=3 ... this line is just show how would it work. with your content in file as example: kent$ awk -F: '{a[++i]=$0;if(i==3)f=$2}i==4{for(x=1;x<=i;x++)print a[x]>f".txt";i=0}' file kent$ head *.txt ==> john.txt <== =====record1 title:javabook author:john path:d: =====record3 title:javabook author:john path:f: ==> paul.txt <== =====record2 title:.netbook author:paul path:f:

Categories : Windows

remove last 14 digits from string, if there are digits
this? $filename = "data-c(festo1-small1);divider-bin-1.4.4;divider-conf-1.3.3-w(1,16);storage-bin-1.5.4;storage-conf-1.5.0-w(1);worker-bin-4.5.1;worker-conf-4.4.1-c(festo1)-win1_20130620123306" $filename -replace 'd{14}$'

Categories : Powershell

Display more digits of p-value digits from adfTest when p-value<0.01
I don't know much about the command you're running, but I looked through the adfTest function and it looks like the do approximation of the p-value based on the approx function and a table of critical values, which means that they can't report P-Values < 0.01.

Categories : R

Format input field to separate the first 4 digits with a period, and the next 2 digits with a period
you can use input boxes of required length ex: <input type="text" maxlength="4">.<input type="text" maxlength="2">.<input type="text" maxlength="4">

Categories : Javascript

show 2 digits max after floating point ... only if it is a float number with more than 2 float digits
I think there is no such short bypass for it. Manually check if it has 2 or more digits after decimal. How to know if it has less one or zero digits after decimal ? Just multiply with 10 and check if it is an integer. If it is, print the number as it is. If it's now use '%.2f' to print it.

Categories : PHP

VB.NET Remainder Function
The remainder is an operator in VB, Mod: If GlobalVariables.TransferTracker Mod 50 = 0 Then … As a general advice, don’t write … = True in your conditions. Its redundancy is redundant.

Categories : Vb.Net

Remainder through recursion
In this case perhaps you need only to move your print up int rem(int a,int b) { x=a; printf("%d ",x); if(x>=b) { x=x-b; rem(x,b); } return x; } But I think you should avoid the use of global variables in a recursive alrotithm. It could make the algorithm very difficult to reason about. Recursive functions are better to be 'pure functions'.

Categories : C

how to check if the / operator has no remainder in C?
use modulous operator for this purpose. if(x%y == 0) then there is no remainder. In division operation, if the result is floating point, then only integer part will be returned and decimal part will be discarded.

Categories : C

C: The Math Behind Negatives and Remainder
Like Barmar's linked answer says modulus in a mathematical sense means that numbers are the same class for a ring (my algebra theory is a bit rusty so sorry the terms might be a bit loosely used:)). So modulus 5 means that you have a ring of size 5. i.e. 0,1,2,3,4 when you add 1 to 4 you are back at zero. so -9,-4,1,6,11,16 are all the same modulo 5 because they are all equivalent. This is actually very important for various algebra theorems but for normal programmers it's pretty much useless. Basically the standards were unspecified so the modulus returned for negative numbers just has to be one of those equivalent classes of numbers. It's not a remainder. Your best bet in situations like this is to operate on absolute values when doing modulo operators if you want basic integer

Categories : C

Python remainder operator
Edit: it's not entirely clear what you meant when you were asking for a remainder operation, the way to do this will depend on what requirements there are on the sign of the output. If the sign is to be always positive divmod can do what you want, it's in the standard library http://docs.python.org/2/library/functions.html#divmod Also you might want to look at the built-in binary arithmetic operators: http://docs.python.org/2/reference/expressions.html If the remainder has to have the same sign as the the argument passed then you'd have to roll your own such as this: import math def rem(x,y): res = x % y return math.copysign(res,x)

Categories : Python

Sort an array by remainder of 4
Since O(3 * N) is O(N), you only need to loop through the array three times: Move the elements e % 4 == 0 to the front, swapping elements along the way; Move the elements e % 4 == 1 to the front, swapping elements along the way; Move the elements e % 4 == 2 to the front, swapping elements along the way; The elements that e % 4 == 3 will be at the end after this. Example: public static void main(String args[]) { int[] a = { 1, 7, 3, 2, 4, 1, 8, 14 , 9}; int current = 0; for (int i = 0; i < 3; i++) { for (int j = current; j < a.length; j++) { if (a[j] % 4 == i) { int b = a[j]; a[j] = a[current]; a[current] = b; current++; } } } System.out.println(Arrays.toSt

Categories : Java

how work around remainder functions?
Well if I understand well you want to determine parameters a and c in your recurrent relation. But you only have one solution of the equation. Your system is underdetermined, you need 3 values Xn+2, Xn+1 and Xn. (http://en.wikipedia.org/wiki/Underdetermined_system) If you know c, then this is obvious : You need to solve a linear equation.

Categories : Algorithm

DCG: Assigning remainder to a variable within DCG {} code
I think you should not use global variables. Instead, add argument(s) to DCG clauses, to get back the values: anything([C|Cs]) --> [C], anything(Cs). anything([]) --> []. otherwise, the remainder is available as last argument of phrase/3, after rules succeded, 'consuming' the heading match.

Categories : Prolog

C++ certainity of Integer Division with remainder
So, instead of integer modulo, you can get two floats then multiply one float with inverse of the divider : 17.0 * 0.33 = 5.61 then floor() it into an integer and subtract : 5.61 - 5 ----> 0.61 then multiply the result with inverse of 0.33: 0.61 * 3 ------> 1.83 then ceil() it 2 ----> this is 17%3 This is 14 times slower than using direct modulus, according to user "Oseiskar " 's benchmarking.

Categories : C++

Logic with spacing when finding remainder
You just need to fix some lines, please, see the comments below: #include <stdio.h> #include <stdlib.h> int main(void) { int i,k,m,l; int add=0; for(i=1;i<11;i++) { printf("%2d: ",i); // align to rigth for(k=1;k<=i;k++) // Invert loop order { m=i/k; if(i%k==0) { // m=i/k; Remove it. Duplicated! add=add+m; printf("%2d ",k); // use 2 digits and print k } else printf(" "); // three spaces } for(l=(10-i);l>0;l--) printf(" "); // three spaces printf("| %2d ",add); // use 2 digits for print add=0; } }

Categories : C

Remainder - My code is not correct, but why is it working?
If you trace through the program, it's actually matching the % 100 == 0 twice first, getting CC, and leaving you with 1000. Then it matches % 1000 == 0, leaving CCM. Finally it reverses the string, leaving you with MCC. Side comment: Interesting approach to the problem as I probably would have used a bunch of >= comparisons building the string in forward order with special cases for the 'subtraction' parts (IV or IX). Although on second read, this solution appears to output IIII and not IV, so the special cases are moot.

Categories : Ruby

Skip remainder of line with fscanf in C
#include <stdio.h> int main(){ FILE *f = fopen("data.txt", "r"); int n, stat; do{ if(1==(stat=fscanf(f, "%d", &n))){ printf("n=%d ", n); } }while(EOF!=fscanf(f, "%*[^ ]")); fclose(f); return 0; }

Categories : C



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