w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Detecting emoticons with regex in javascript
[:=;]-?[)(|\/][]|[)(|\/][]-?[:=;] This looks like an unholy mess from hell until you break it down: [:=;] matches one : or one = or one ; [)(|\/][] matches one ), (, |, (backslashed because it is a metacharacter), /, ] (backslashed because it is a metacharacter) or [ (backslashed because it is a metacharacter). (We didn't need to backslash ) or ( because they are not metacharacters inside of a character class). The | in the center means 'match left of me OR match right of me' and then I write the same two character classes but in reverse to match smileys that are reversed in direction. I think the problem with your regex is here: []/)] You forgot to escape the first ] with a so it is treated as ending the character class prematurely. The other problem is that you thought forward

Categories : Javascript

regular expressions emoticons
It looks to me like your regex is working, and that m should indeed not be None. >>> re.search('^(:(|:))+$', ':)').group() ':)' >>> re.search('^(:(|:))+$', ':)').group() ':)' >>> re.search('^(:(|:))+$', ':):(').group() ':):(' >>> re.search('^(:(|:))+$', ':)?:(').group() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'NoneType' object has no attribute 'group' However, a few things are questionable to me. this will only match strings that are 100% emoticons is fileid really what you're searching?

Categories : Python

PHP For Loop str_replace emoticons
Restructure your array like this: $emotes = [ ":)"=>"<img class='emoticon' src='smile.png' />", ":D"=>"<img class='emoticon' src=grin.png' />" ]; Then use strtr: $contentWithEmotes = strtr($content,$emotes);

Categories : PHP

Using emojis/emoticons in DocPad
Sure, so you could make a plugin that utilises the renderDocument event that does a find and replace on opts.content for the emoji source and replaces it with the html equivalent. Something like: opts.content = opts.content.replace(/:([a-z0-9]):/i, function(a,b,c,d){ return 'replacement lookup'; });

Categories : Misc

Incorporating emoticons into a scikit model
Both options should work. There's a third option, which is to tokenize your samples manually and feed them to a DictVectorizer instead of a CountVectorizer. Example using the simplest tokenizer there is, str.split: >>> from collections import Counter >>> from sklearn.feature_extraction import DictVectorizer >>> vect = DictVectorizer() >>> samples = [":) :) :)", "I have to push the pram a lot"] >>> X = vect.fit_transform(Counter(s.split()) for s in samples) >>> X <2x9 sparse matrix of type '<type 'numpy.float64'>' with 9 stored elements in Compressed Sparse Row format> >>> vect.vocabulary_ {'a': 2, ':)': 0, 'I': 1, 'to': 8, 'have': 3, 'lot': 4, 'push': 6, 'the': 7, 'pram': 5} >>> vect.inverse_transform

Categories : Python

How to get href text which contains .xls or .xlsx text in an anchor tag using regex
Many potential problems doing it this way, but using JavaScript: var re = new RegExp(/<as*[^>]*s*hrefs*=s*((?:[^ ]|[ ])+)((.xls)|(.xlsx))s*[^>]*>.*?</a>/ig); txt = 'ok, here you go: <a href="test.xls">test file</a> and <a href="http://not.test.com">not file</a>, but another <a href = "http://www.xls.com/test.xls">test file</a>!'; txt.match(re) => ['<a href="test.xls">test file</a>', '<a href = "http://www.xls.com/test.xls">test file</a>']

Categories : C#

Regex for text outside <% %>
Since regular expression matches must be contiguous (i.e. have no gaps) there is no single expression to match all text outside the tags. However, you can still do it if you combine regex with C#'s string facilities, like this: var outside = string.Join("", Regex.Split(inputString, "<%.*?%>")); If the inside of the tag may not contain percentage characters, you can optimize your regex to avoid backtracking by using this expression instead: <%[^%]*%>

Categories : C#

regex to get all text outside of brackets
you can do this: outside = re.findall(r"[^[]+(?=[[^]]*]|$)", example_str) In other words: All that is not an opening square bracket followed by something inside square brackets or the end of the string

Categories : Python

Regex to Split any XML Tag on Text Using PHP
Sorry I just realized, I got an answer from my previous question: Count Words on XML Text Using PHP I am just add little bit of code so I could got an output like this question, here's the code: $xml_text = 'The <tag1>quick brown fox</tag1> <tag2>jumps over</tag2> the lazy <tag1>dog</tag1>'; $doc = new DOMDocument(); $result = $doc->loadXML(sprintf('<root>%s</root>', $xml_text)); function utf8_count_words($string) { return (int)str_word_count($string); } $word_count = 0; $array_text = array(); $i = 0; foreach ($doc->documentElement->childNodes as $node) { switch ($node->nodeType) { case XML_ELEMENT_NODE: $array_text[$i] = "<".$node->nodeName.">".$node->nodeValue."</".$node->nod

Categories : PHP

Search text using c# regex
I'll give you a hint... The regex you want is rect (.*)s?=s?null You'll now need to learn how to use the regex class to run that, and you might find MatchCollections and Groups interesting. That's now given you enough to solve your problem in 10 minutes, but you have to do some reading yourself...

Categories : C#

How to find text in html using regex
As pointed out, Regex is a bad idea. I think to parse HTML probably the most well known library is jSoup and a very nice tutorial by MK Yong is here

Categories : Java

Skip text between quotes in Regex
With all of the possible cases involving mixed sets of quotes, a regex may not be your best option here. What you could do instead (after using your current regex to filter for everything but quotes), is count the number of quotes before and after the occurrence of textToFind. If both counts are odd, then you have quotes around your keyword and should scrap the line. If both are even, you've got matched quotes elsewhere (or no quotes at all), and should keep the line. Then repeat the process for double quotes. You could do all this only walking through the string once. Edit to address the update that you're searching through code: There are some additional considerations to take into account. Escaped quotes (skip over the character after an escape character, and it won't be counted). Co

Categories : C#

Regex replace to reorder text
well you can use preg_replace_callback to do such thing here's an example but you will be using globals which is really a dirty solution: $str = 'abcdefghijkl <iframe....></iframe> mnopqrstuvwxyz <iframe....></iframe>'; global $myText; global $myIframe; preg_replace_callback("/([^<]+)(<iframe[^>]+>[^<]*</iframe>)/i", function($matches) use ($myText) { global $myText, $myIframe; $myText .= $matches[1]; $myIframe .= $matches[2]; }, $str); echo $myIframe."<br>".$myText;

Categories : PHP

How to split a text by a whole line using regex
You forgot to use appropriate quantifier. You should split on 1 or more -. Currently you are splitting on just 1. Also, point to note, [ ][ ]? will not match single , you should consider that also: Try using this regex: Regex.Split(text, "-+(?: | | )?"); You can make the group captured to allow matching the last ---, which doesn't end with newline.

Categories : C#

Parsing big text file using regex
You can use islice. from itertools import islice file = open('file.txt', 'r') while True: slice = islice(file, buffer) to_process = [] for line in slice: to_process.append(line) if not to_process: break #process to_process list file.close() buffer is the number of lines you want to read at a time (you have to define the int).

Categories : Python

How to color text using Regex in android
Take a look at SpannableString and SpannableStringBuilder. An example of using the SpannableStringBuilder is available at http://stackoverflow.com/a/16061128/1321873 You could write a method that accepts the non-styled String and returns a CharSequence like so: private CharSequence getStyledTweet(String tweet){ SpannableStringBuilder stringBuilder = new SpannableStringBuilder(tweet); //Find the indices of the hashtag pattern, mention pattern and url patterns //and set the spans accordingly //... return stringBuilder; } and then use the return value from the above to set the text of the TextView TextView tView = (TextView)findViewById(R.id.myText); tView.setText(getStyledTweet(tweet));

Categories : Java

Javascript regex: how to match on the whole text?
. does not match line breaks and unfortunately JavaScript does not have a s switch to make it match line breaks as well. So you can’t use . or only together with [ ] like: /(.|[ ])+/ It would be simpler to use an expression other than . like [^], which will match any character. So: /[^]+/

Categories : Javascript

Add some text in loaded xml using Javascript and regex
Firstly, using Regex on SVG is a pretty bad idea (slightly different topic, but still applicable RegEx match open tags except XHTML self-contained tags) You should be able to manipulate with jQuery (or similar) like you would any other DOM-like structure. I've just tested this (using the .wrap() call, borrowed from Peter's answer), and the result is an object that matches the structure you require: <!DOCTYPE html> <html> <body> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script> var mySvgMarkup = '<!--?xml version="1.0" ?-->' + '<svg xmlns="http://www.w3.org/2000/svg" width="822" height="600">' + '<defs></defs>' + '<g id="edges" transform="translate(245.296 61.75) scale(0.630539)">' + '</

Categories : Javascript

Extract text before _ in a string using regex
You can try something like .*?(?=_) . matches any character and *? is a reluctant quantifier. (?=_) is a positive lookahead to ensure our match is followed by an _. If you want to only extract characters that occur at the beginning of a string you can add the ^ anchor: ^.*?(?=_). ^ matches the position before the first character in the string.

Categories : Regex

Regex pattern for text between 2 strings
The characters [ and ] have a special meaning with regular expressions - they define a group where one of the contained characters must match. To work around this, simply 'escape' them with a leading character: string patternstart = "Session["; string patternend = "]"; An example "final string" could then be: Session["(.*)"] However, you could easily write your RegEx to handle Session, Querystring, etc automatically if you require (without also matching every other array you throw at it), and avoid having to build up the string in the first place: (Querystring|Session|Form)["(.*)"] and then take the second match.

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

Matching arabic text with regex
Use this character block p{InArabic}+ In java Unicode scripts, blocks, categories and binary properties are written with the p and P(negated effect) Scripts are specified either with the prefix Is or by using the script keyword(supported scripts) Blocks are specified with the prefix In or by using the keyword block(supported blocks) Categories may be specified with the optional prefix Is or using keyword general_category or gc(supported categories) Binary properties are specified with the prefix Is (supported properties) REFERECE

Categories : Java

A regex to highlight words in text
I dont remember the exact syntax of how it would look in javascript, but it would be something like for(var input : inputs){ string.regexReplace("("+input+")","<b>1<>") }

Categories : Javascript

Regex and matching all all of text and not substring
Add start ^ and end $ anchors: ^([a-z]{1,3}[.]{1})$ Incidentally, you don't need the {1} - that's implied. This is the same as your regex: ^([a-z]{1,3}[.])$

Categories : Regex

Python replace text (regex?)
If you look at the documentation of re.findall(), it will return a list of all non-overlapping matches in the string. Hence you cannot do link.replace() since link is a list, not string. You have to loop over each element in link and do the replace. For example, links = re.findall(pattern,htmltext) downloadlinks = [] for link in links: downloadlinks.append(link.replace("*text to replace*", "*replace with*")) print(downloadlinks) Edit (convert list to str): links = re.findall(pattern,htmltext) downloadlinks = '' for i, link in enumerate(links): if i == 0: downloadlinks += link else: downloadlinks += ' - ' + link print(downloadlinks)

Categories : Python

How to add text with replace function and regex?
I don't think Find and Replace is flexible enough to do what you want i.e. append 5 to each cell. The simplest way would be to use this formula to create a new column and then delete the original. [ I'll assume your data are in column A ] =5 & A1 You could also do it through VBA if you like. Sub AppendFive() Dim cl As Range For Each cl In Range("A1:A10") cl = 5 & cl Next cl End Sub

Categories : Regex

Remove block of text in vim with regex
You could move the cursor to the space before the first 0x00004341, press CtrlV to enter visual mode, G to go do the end of the buffer, E to go to the end of the line, then d to delete. Or, you could run: %s/^(.* )[^ ]+$/1/g

Categories : Regex

Javascript Regex to urlify text
I would write a helper function that takes a single url string as input and return the anchor tag with that url on match. Parse the big string into an array with each element matching a corresponding [] pair. Then it's just a matter of iterating over this array and passing it into the helper function: function urlify(s) { var urlpat = /[((https?|ftp)://w+[^]]*)]/i; var matches = urlpat.exec(s); var anchor_url = '<a href="%1">%1</a>'; return matches ? anchor_url.replace(/%1/g, matches[1]) : ''; } instring = '[http://www.someurl.com/path/to/resource/?some=params&crazy_chars=true_0_1_0_1]' + '[@ID 65421]' + '[http://google.com]'; var arr = instring.match( /([[^]]+])/g ); for(var each in arr) { arr[each] = urlify(arr[each]); } arr will cont

Categories : Javascript

Regex to match surrounding text
Idea: Capture 'anything' in a capturing group in regex. Then, back reference it in the replacement. For example: search for something[([^]]*)] and replace with somethingElse($1).

Categories : Regex

Extracting infromation from text using regex
This preg_match_all should work: $s = 'Rating: Explicit Score: 17 Tags: apron blonde_hair brown_eyes itaru_chokusha kirigaya_kazuto long_hair sword_art_online yuuki_asuna User: openui'; if (preg_match_all('#s*(.+?(?=((^|s)[A-Z][a-z]*:s*|$)))#i', $s, $arr)) print_r($arr[1]); OUTPUT: Array ( [0] => Rating: Explicit [1] => Score: 17 [2] => Tags: apron blonde_hair brown_eyes itaru_chokusha kirigaya_kazuto long_hair sword_art_online yuuki_asuna [3] => User: openui )

Categories : PHP

Parsing text in a file with regex
You read the file already. The file pointer is now at the end and you won't read any more data. Store the file data once: contents = f.read() print contents # prints '22 test 333' print data.findall(contents) # outputs ['22'] Alternatively, seek back to the start: print f.read() # prints '22 test 333' f.seek(0) print data.findall(f.read()) # outputs ['22'] or reopen the file.

Categories : Python

RegEx: text immediately after the last opened parenthesis
This is similar to this problem. And since you are using PCRE, using the recursion syntax, there is actually a solution. / (?(DEFINE) # define a named capture for later convenience (?P<parenthesized> # define the group "parenthesized" which matches a # substring which contains correctly nested # parentheses (it does not have to be enclosed in # parentheses though) [^()]* # match arbitrarily many non-parenthesis characters (?: # start non capturing group [(] # match a literal opening ( (?P>parenthesized) # recursively call this "parenthesized" subpattern # i.e. make sure that the contents

Categories : Regex

Check text for multiple RegEx matches
IsMatch just returns a boolean, so you should be able to use ||. You may have a typo. Check out the single pipe between your first two !Regex.IsMatch statements: if (!Regex.IsMatch(text, @"[trf]h[ec]", RegexOptions.IgnoreCase) | !Regex.IsMatch(text, @"date", RegexOptions.IgnoreCase) || ... Also, if you only want to return false if none of the expressions in the second if statement are a match, you probably want to use the && operator instead. if ((text doesn't match 1st expression) and (text doesn't match 2nd expr) and ... ) return false;

Categories : C#

Parsing plain text with AWK regex tools
Code for GNU awk BEGIN { FS = "[ .,]"} { for (i = 1; i <= NF; i++) { if ($i ~ /[0-9]/){ print($i, $(++i)) } } } $awk -f a.awk file 20 m 1/2 kg 5 kg 10 m/s2

Categories : Regex

Only capture digits instead of the other text in input for a regex like below
Just change the boundaries of the second group to only include the digits. To also save the "H.B." part, add paranthesis around that part too: ^(?:(\S+)\s+)*?(\d+)\S+\s+(?:No\.\s+)?(\S+)(?:\s+\(.*?\))?$

Categories : Java

Using regex to capture text in parentesis if they exist
If you try to match line by line, you can use this regex: ^(.+?)(?: ((.+)))?$ I added the start of line anchor and end of line anchor, then put the space in the first non-capturing group, so that the title without any other details can be captured. I changed the * operator to ?, since I don't think you'll have more than one pair of brackets. Change if you think you do have more. I removed the second non capturing group as the end of line anchor will ensure it's the end of the line. Demo here.

Categories : Python

How to replace image URL(plain text) with Regex
You're almost there, Herry. When you're doing replacements, there are some metacharacters available for you in the replacement string. $1 will insert the first matched group, $2 will insert the second matched group, and so on. However, in your case, you can use the even more general $&, which will insert the entire matched regex, so you can even drop the unnecessary group in your regex: var isImgUrl= /https?://.*.(?:png|jpg|gif)/i; var txt=document.getElementById('comment'); txt.innerHTML=txt.innerHTML.replace(isImgUrl,'<img src="$&"/>'); I'm guessing here, but you probably also want to include the common JPEG extension .jpeg (as well as the shorter .jpg). I also you suspect you want to replace all such matches; what you have will only replace the first. To replace al

Categories : Javascript

regex complicated scenario during the text of markdown
Posting my comment as an answer. Try the below. Sorry, if this is still not what you want. regex = new RegExp(/(- [sS]+?)(?:( ){2,}(?= |-))/g); inputString = '- sometext - sometext followingText - sometext - sometext - sometext'; outputString = inputString.replace(regex,'$1 WhiteSpace '); console.log(outputString);

Categories : Javascript

Regex in sed to remove hyperlink and keep link text
although shellter is right, here's one: xmpl='<a ..potential-other-stuff.. class="lexicon-term" ..potential-other-stuff.. >medium</a>' echo $s | sed 's|<a [^>]* class="lexicon-term" [^>]*>([^<]*)</a>|1|' some comments: sed allows arbitrary delimiters. here | is better than /. [^>] instead just . stops the pattern from spanning across multiple a-tags

Categories : HTML

Regex to extract only text after string and before space
you can have positive lookbehind in your pattern. (?<=BookTitle).*?(?=s) Lookahead and Lookbehind Zero-Width Assertions

Categories : Regex



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