Menu
  • HOME
  • TAGS

Match words of permutations of another word using regex [duplicate]

regex,permutation,matching,words

Using lookaheads, with "leap" as an example: \b(?=[a-z]*l)(?=[a-z]*e)(?=[a-z]*a)(?=[a-z]*p)[a-z]+\b Fiddle: http://refiddle.com/12u4 EDIT: I added \b anchors (word boundaries); the leading one is especially important, otherwise "appeal" might be captured three times ("appeal", "ppeal", "peal"). Feel free to use other anchors when appropriate (e.g. ^...$). By the way, this approach is also...

How to calculate the frequency of word in Zipf's law?

collections,task,frequency,words,ir

I humbly direct you to the wikipedia article on Zipf's Law, Formally, let: N be the number of elements; k be their rank; s be the value of the exponent characterizing the distribution. Zipf's law then predicts that out of a population of N elements, the frequency of elements of...

Count number of word occurrences in a string

c#,string,count,words

Your loop contains two problems: You can't use a key if it doesn't exist (Test with ContainsKey) You should loop until index < words.Length for (int index = 0; index < words.Length; index++) { string word = words[index]; if(!wordsAndCount.ContainsKey(word)) wordsAndCount.Add(word, 1); else wordsAndCount[word]++; } You could also trim away a...

MS Excel: Count Number of Words Between Two Different Characters in a Text String

excel,count,character,between,words

Place this in B2, changing "%" and "$" as required: =LEN(MID(B2,FIND("$",B2)+1,FIND("%",B2)-FIND("$",B2)-1))-LEN(SUBSTITUTE(MID(B2,FIND("$",B2)+1,FIND("%",B2)-FIND("$",B2)-1)," ",""))+1 ...

PHP explode uppercase words

php,explode,uppercase,words

Don't use explode: $up = preg_split('/\s([^A-Z]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE); Debuggex Demo...

Why do I get such a messed up output?

c,arrays,loops,words

There are a few problems in you code: for(;i < strlen(point); i++) //seperates strings from each other When this line is executed the value of i is already strlen and therefore the following for is not executed. Add i=0 to fix it. You should use sizeof not strlen, otherwise you...

Prolog Numbers to Words

string,recursion,prolog,integer,words

The trick to solving issues where the first or the last action must be different from the rest of the actions is to split your predicate in two. In this situation, you can make your top-level predicate that calls word(digit), and then calls another predicate that prints the "tail" of...

Substituting percentage of words at random indexes in String array

android,arrays,string,random,words

First, calculate how many words you want to replace: int totalWordsCount = words.length; double percentageOfWords = 0.20; int wordsToReplaceCount = (int) Math.ceil( totalWordsCount * percentageOfWords ); Then, knowing how many words you want to replace, get that many random indexes, and just swap words at those indexes: for (int i=0;...

Haskell words implementation

haskell,words,fold

OK, so let's try this: step x acc = if isSpace x then if null (fst acc) then acc else ([], (fst acc) : (snd acc)) else (x : fst acc, snd acc) words' xs = snd $ foldr step ([], []) xs Now let's walk this through, one step...

RegEx for exactly two or three words

javascript,html,regex,unicode,words

Just replace your new definition of "word" character to all the \w. This is for exactly 2 words, with exactly 1 space in between: /^$|^[a-zA-ZčČćĆđĐšŠžŽ-]+ [a-zA-ZčČćĆđĐšŠžŽ-]+$/ For exactly 2 or 3 words: /^$|^[a-zA-ZčČćĆđĐšŠžŽ-]+ [a-zA-ZčČćĆđĐšŠžŽ-]+( [a-zA-ZčČćĆđĐšŠžŽ-]+)?$/ Note that I have removed the space in your character class, since it shouldn't be...

Word in a java string

java,string,words

A simpler way would be to use regular expressions (that probably defeats the idea of writing it yourself, although learning regexes is a good idea because they are very powerful: as you can see the core of my code is 4 lines long in the countMatches method). public static void...

Python2 word input if-statement script

python,if-statement,words

raw_input returns a string already, so you don't have to convert it to string again. No need str("yes") this. Also your intention is wrong. It must be; if answer == "yes": Your whole script must be like; from time import sleep answer = raw_input("Do you enjoy your work?\n") print answer...

a program to reverse each word in a string( ive read the previous solutions but im looking for one using the functions i only here [closed]

c,string,reverse,words

#include <stdio.h> #include <string.h> #include <conio.h> int main(void){ char A[81][81] = {0}; int t=0,j=1,k=0,l; puts("Input a sentence (max 80 character)"); scanf("%80[^\n]", A[0]);//'gets' has already been abolished, it should explore a different way. while (A[0][t] != '\0'){ if(A[0][t] == ' '){ ++j; k=0; while(A[0][t] == ' ')//Skip spaces ++t; } else...

C program to count words in a given string/sentence?

c,arrays,count,character,words

You are using the assignment operator = for comparison if(a[i]=' ') you need == if(a[i] == ' ') some people use this if (' ' == a[i]) to prevent this kind of mistake....

Clojure - how to count specific words in a string

clojure,count,words

One way to do it is to use regular expressions and re-seq function. Here is a "naive" example: (count (re-seq #"and" string)) And here is the same code, written with treading macro ->>: (->> string (re-seq #"and") count) It will count all appearances of sub-string "and" in your string. It...

Classification based on List of Words Python

python,mongodb,classification,words

In addition to string comparisons and control flow statements, a list comprehension will be useful here. text = "seeking help on possible homework task" raw_words = text.split(" ") positive_words = ['seeking','help'] negative_words = ['homework'] positive_score = len([word for word in raw_words if word in positive_words]) negative_score = len([word for word...

Word palindrome in C

c,text,spaces,words

EDIT: Code below works as following: input file is read char by char if char read isn't alphanumeric, then it is written to the output file else, the whole word is read with fscanf if word is not a palindrome, then write to the output file #include <stdio.h> #include <ctype.h>...

How can I fade in changing words with .html? [duplicate]

jquery,html,fadein,words

fadeOut the previous words and then fadeIn the next word. $("#random-word").fadeOut('slow', function() { $(this).html(words[i]).fadeIn("slow"); }); Demo...

Python regex : detect a word with duplicated chars [closed]

python,regex,artificial-intelligence,words

import re p = re.compile(r'(.)\1+') test_str = "heeeey" subst = r"\1" result = re.sub(p, subst, test_str) You can do it through re.sub.Here we capture any character which are repeated ahead and replace all by \1 .So all the repetitions will be gone. See demo. https://regex101.com/r/cK4iV0/7#python...

How do would I alphabetize the strings in my character array?

c,arrays,char,words

When you do get it working, I think you are in for a surprise. The sort_string function has nothing whatsoever to do with sorting words in an array of pointers instead, it sorts characters in an array. For example: $ ./bin/str_sort_words Enter a string: a quick brown fox jumps over...

Java locking words so they can't be used

java,locking,keylistener,words

You can use a Set containing bad words and then just test whether the typed word is present in set E.g.(hello is the bad word in example below). import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.io.*; import java.net.*; import java.util.*; class Chat implements KeyListener{ JTextArea incoming; JTextField output, name; JButton...

how do you give different names to str_replace words?

php,str-replace,words

Here is my solution $findStr = 'car'; $str = 'yadadyayayay car yayayaya car aksdkjasd car car car car car car car'; $count = substr_count($str, $findStr); $str = preg_replace("/$findStr/", "$findStr ", $str); for($i=1; $i <= $count; $i++) { $str = preg_replace("/$findStr\D/", $findStr . $i, $str, 1); } echo $str; This will...

PHP replace multiple words

php,words

<?php $wordsToKeep = array('car', 'circle', 'roof'); $text = 'I have a car with red one circle at the roof'; $words = explode(' ', $text); $filteredWords = array_intersect($words, $wordsToKeep); $filteredString = implode(' ', $filteredWords); $filteredString would then equal car circle roof. See http://php.net/manual/en/function.array-intersect.php...

Javascript - regex - how to remove words with specified length

javascript,regex,words

The problem with greek characters is because of \b. You can take a look here: Javascript - regex - word boundary (\b) issue where @Casimir et Hippolyte proposes the following solution: Since Javascript doesn't have the lookbehind feature and since word boundaries work only with members of the \w character...

How do I find all unique words(no duplicates)?

python,list,input,store,words

Here is a snippet which might help you: new = 'this is a bunch of words' new2 = 'this is another bunch of words' unique_words = set(new.split()) unique_words.update(new2.split()) sorted_unique_words = sorted(list(unique_words)) print('\n'.join(sorted_unique_words)) Update: If you're only interested in words that are common to both files, do this instead: unique_words =...

looking for 1-3 words preceded by 4 digit number followed by non alpha characters or 1-4 specific words

regex,excel,between,words

You can use the following regex equivalent to all your 121 patterns and your exclusion requirement: \b\d{4}\b\s*\b[A-Z]{3,11}\s*\b(?!(INTE|MANU|PMNT|Payment)\b)[A-Z]{3,11}\s* ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ See DEMO...

Word matching in corpus of text is very slow

php,mysql,sql,lookup,words

You have a fairly small reference table (your lexicon) and an enormous corpus of text (table 1). If I were you I would start your program by slurping the entire lexicon from the table into a php array in memory. Even if all your words are 20 characters in length...

Split list of strings into list of lists of strings

string,haskell,dictionary,words

The type signature of 'map' is map :: (a -> b) -> [a] -> [b] The type signature of 'words' is words :: String -> [String] Therefore, the type signature of 'map words' is map words :: [String] -> [[String]] Hey, that's exactly what you want! Let's give it a...

Can't get my word randomizer script to loop properly

javascript,random,words

Splice will remove word from your array . words.splice(rnd, 1); After the 20th element there is nothing left to iterate. As @Jamiec said you will need a continuous loop. You can also use setTimeout(); to loop continuously (should be less CPU heavy than while(true) ) Try something like this (slightly...

Java words reverse

java,string,words

From adding debug output between each method call it's easy to determine that you're successfully reading the input, counting the words, and initializing the array. That means that the problem is in generate(). Problem 1 in generate() (why "HERE" is duplicated in the output): after you add w to your...

How do I display 3 randomly selected words from a list in set order in Javascript?

javascript,list,select,random,words

You can use this code to get the string that you want. You can add in each array any number of words that start with the letters.. Then, the variable acron will hold the string that you want. You can inject it wherever you need. Since I do not know...

How to not separate on dash/hyphen when using lodash _.words?

javascript,arrays,regex,lodash,words

The initial case can be solved by this: _.words(['user1,user2,user3-adm'], /[^,]+/g); Result: ["user1", "user2", "user3-adm"] [EDITED] If you want to add more separators, add like this: _.words(['user1,user2,user3-adm.user4;user5 user7'], /[^,.\s;]+/g); Result: ["user1", "user2", "user3-adm", "user4", "user5", "user7"] Last snippet will separate by: commas (,), dots (.), spaces (\s), semicolons (;) Alternatively you...

Replace words of text area

javascript,regex,replace,words

If <textarea>, then you need to use .value property. document.getElementById("eC").value = newText; And, as mentioned Barmar, replace() replaces only first word. To replace all word, you need to use simple regex. Note that I removed quotes. /g means global replace. var newText = text.replace(/hello/g, '<b>hello</b>'); But if you want to...

Recursively reversing words in a string

c++,recursion,reverse,words,sentence

It's not as easy as you might think. You need to change the location where the printing command is called and place it below revSentence() recursive call, this is called post-order traversal, while the one you are doing is called pre-order traversal. You also need a stack to push...

Copy the first N words in a string in java

java,string,text,words

String myString = "Copying first N numbers of words to a string"; String [] arr = myString.split("\\s+"); //Splits words & assign to the arr[] ex : arr[0] -> Copying ,arr[1] -> first int N=3; // NUMBER OF WORDS THAT YOU NEED String nWords=""; // concatenating number of words that...