w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Sublime Text 2 - Regular Expression Find and Replace
Option+Cmd+F: Place into the find field: $([0-9]{0,2}) Place into the replace field: 1 $ The backslash + number indicated which capture group to place in there.

Categories : Regex

find the appropriate regular expression
Not sure why you need this but suppose s is your html file then this regex will find what you look for.. import re m = re.search(r"<div class="pro_blk_trans_titre">(.*)</div>", s) print(m.group(1).strip().encode("utf8")) # page1: b'Margaux, Rouge' # page2: b'2xc3xa8me Vin, Saint-Julien, Rouge'

Categories : Python

Find and Replace using Regular Expression
Regular expressions are literals or objects in JavaScript, not strings. So: /(w*W*)of(w*W*)/g or: new Regexp("(\w*\W*)of(\w*\W*)","g");

Categories : Javascript

Regular Expression. Find integers only
You can use negative lookbehind and lookahead, if that's supported by your regular expression engine. The regular expression would be: (?<!.)d+(?!.) The lookbehind ensures that the string of digits does not begin with a ., so that something like .5 won't be matched. The lookahead ensures that the string of digits does not end with a ., so that 5. won't be matched.

Categories : Regex

Find the regular expression itself within the string and replace it
Use the i modifier for case in sensitive regular expressions: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php

Categories : PHP

Why does my Python regular expression find two matches?
[...], which is called a character class, matches a single character. You probably want: (?:0x)?d+

Categories : Python

Regular expression to find and replace conditionally
I use regex (?<=W|^)MECH(?=W|$) to get if inside the string contain whole word MECH like this. Is that what you need?

Categories : Regex

What's the regular expression to find the last digit in a string?
You can use this one : (d)[^d]*$ EDIT : You initially mentioned only a match, no language and no replacement. For your C# replacement, you should use private string InsertFinalDigitHyphen(string data) { return Regex.Replace(data, @"(d)(D*)$", " $1$2"); }

Categories : C#

How to find matching key from array with regular expression
foreach($array as $key=>$value) { preg_math('compare_session_(.*?)',$key,$mathch); if($match[1] AND in_array($value,$out)=== false) { $out[] = $value; } } var_dump($out)

Categories : PHP

Find a XML tag inside log file using Regular Expression?
Try the following this works for both <statusCode>0</statusCode> and <ns2:statusCode>0</ns2:statusCode> /<(ns2:)?statusCode>0</(ns2:)?statusCode>/

Categories : Regex

How to find parts of Regular expression - integers?
You can follow the second capture group with ? to make it optional: var da = str.match(/(+7)(d{3})?/); // -----------------------------^ Then for the string "+7", the match will succeed, da[1] will be +7, and da[2] will be undefined. Update: And similarly for the third capture group you've added to the question. :-)

Categories : Javascript

Find a table's last cell by regular expression
Best you can do with regex is: <td(([^<]|<(?!/td>))*)</td>s*</tr>(?!(.| | )*<tr) But this is kinda ugly, resource intensive and breaks when you have nested tables. A better route is indeed to use an XML or HTML parser for whichever programming language you're using. If you want to select the last cell from EVERY row, as your updated question suggests, leave out the negative lookahead like so: <td(([^<]|<(?!/td>))*)</td>s*</tr> Working example here: http://refiddle.com/gt2

Categories : Regex

python regular expression could not find all images files
Your expression is too greedy. Reign it in: re.compile("<img src='([^']*)jpg'") However, the better approach is to use a proper HTML parser, like BeautifulSoup: for image in soup.find_all('img', src=True): print image['src'] finds all <img /> tags with a src attribute, for example.

Categories : Python

Regular expression to find "src" attribute of HTML "img" element in PHP
The parts that reads ([^s]+) means select anything that isn't a space. Maybe try something like: /src="([^"]+)"/ Which is select anything that isn't a double quote.

Categories : PHP

Regular Expression to find matches of String series
The regex for the pattern you are looking for is (.*?).(.*?) .*? is a reluctant greedy quantifier, meaning that will match as it can before the next match in the regex You also need to escape characters like . ) and (

Categories : Regex

regular expression to find word after a character and before another one if included
I believe the best pattern would be: /^[^#?]+/media-group/([^?]+).*$/ which breaks out as: ^ - start of string [^#?]+ - one or more non-hash, non-question-marks / - literal char media-group - literal chars / - literal char ( - start capture group [^?]+ - one or more chars non-question-marks ) - end of capture group .* - zero or more chars $ - end of string The reason this works is because [^?]+ is "greedy" in that it will attempt the longest possible match, which encompasses either a question-mark followed by arbitrary chars, or nothing, since all chars to the end of the string have already been captured in the non-question-mark capture group. So, us

Categories : Javascript

regular expression to find special character & between xml tags
You can use lookahead: Replace &(?!w*;)(?=[^<]*</value>) by &amp; This works by specifying two lookaheads. The first lookahead (?!w*;) prevents valid HTML escape sequences from being matched. The second lookahead (?=[^<]*</value>) specifies that a </value> tag must follow the text (after some amount of non-XML-tag content). Try it here.

Categories : Java

Find regular expression for my twitter time stamp (PHP)
You can try this regular expression: about [0-9]{2}/[0-9]{2}/[0-9]{2} in order to make sure about the syntax you generate you can test it using online regex testers website. Here is an example website: http://regexpal.com/

Categories : PHP

Regular expression find and replace to wrap tags
You may try this: using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { string input = "Hello World!", keyword = "Hello"; var result = Regex .Replace(input, keyword, m => String.Format("<b>{0}</b>", m.Value)); Console.WriteLine(result); } }

Categories : C#

Regular expression returns empty array in php even though the regular expression is correct
I assume you were trying to do a noncapture group for <price... but you missed the :. Or you should take out the question mark. If the price group is optional, try like the regex below. You should use the following website to help you with regex. I find it extremely helpful. <td>( |s)*?(<span( |s|.)*?</strong>( |s)*?$(<price>)*([0-9.]*).*?)$(.*?)( |s)*?< Edit live on Debuggex In the above example, your first match would have the following captures: 0: "<td><span class="offer"><strong>xscre:<br></strong>$299 xxxxx&x;xx<span class="fineprint_number">2</span></span><br>de&ea;s $399<" 1: "" 2: "<span class="offer"><strong>xscre:<br></strong>$299 xxxxx&x;xx<span clas

Categories : PHP

Python Regular Expression - Regular Expression that finds one pattern per line?
There's no point loading the whole file into memory to do an re.findall and by doing so you lose the ability to short circuit upon finding the first match import re with open('data.txt') as f: print sum(1 if re.search(r"Line", line) else 0 for line in f) 5

Categories : Python

Regular expression with dynamic text
You could do String newTemp = temp.replaceAll("core-\w+", "testingPlatform"); where w+ matches one or more word characters ([a-zA-Z_0-9]) Filenames can contain unicode characters so better String newTemp = temp.replaceAll("core-\p{L}+", "testingPlatform");

Categories : Java

Python regular expression: about getting text
According to the screenshot your text is something like "108, 109" but reqular expression is parsing "(108, 109)". Use: mob_x, mob_y = re.findall(r"([0-9]+), ([0-9]+)", item_index.GetText())[0]

Categories : Python

How to get text from attribute with for example regular expression?
You could just split on the single quote character and take the second value returned: $(".click").click(function(){ var text = $(this).data('test').split("'")[1]; alert(text); }); Working Demo

Categories : Javascript

Regular expression to find numbers inside HTML tags
This matches 123 in <div>123</div> for example: [0-9]+(?:.[0-9]*)|(?<=^|>)d+(?=<|$) This regex was edited from the link you provided: http://regexr.com/?361gc

Categories : Regex

Regular expression to find position of the last alpha character that is followed by a space?
I'm not sure about REFindNoCase, but I think you can try with REReplaceNoCase. I hope that CF can take back references like most regex engines do: REReplaceNoCase(MyString, "(.*[a-zA-Z]+)s.*", "$1", ALL); EDIT: for the backreference, it appears that you use the backslash instead of the dollar sign: REReplaceNoCase(MyString, "(.*[a-zA-Z]+)s.*", "1", ALL); And if it goes well, you should have something like this. .* matches anything besides a newline character,  matches word boundaries, [a-zA-Z]+ are for alphabet characters and s is for the space just after it. The greediness of the first .*'s is being exploited here to capture as much as possible until you get the last word followed by a space. And I guess you can add the ellpses after the $1 like so: REReplaceNoCase(MySt

Categories : Regex

Javascript regular expression to find double quotes between certain characters
Given Stack Overflow's "we don't do your homework" principles, I don't think I'm going to work through the whole solution, but I can give you some pointers in half-finished code. var xySearch = /this regex should find any text between XXX...YYY/g; // note the g at the end! That's important var result; var doubleQuoteIndices = []; // note the single-equals. I avoid them when possible inside a "condition" statement, // but here it sort of makes sense. while (result = xySearch.exec(str)) { var block = result[0]; // inside of the block, find the index in str of each double-quote, and add it // to doubleQuoteIndices. You will likely need result.lastIndex for the absolute position. } // loop backwards through str (so that left-side replacements don't change right-side indexes) // to rep

Categories : Javascript

Python Regular Expression to find the last occurrence of whitespace in a certain pattern
re.split by s+ and take the second last token in the returned list (e.g. using index -2). http://docs.python.org/2/library/re.html#re.split

Categories : Python

URL Anchor Text Regular Expression Puller
Getting your answer from the DOM would be a lot easier. For example: var links = document.getElementsByTagName("a") for (foo in links){ if(links[foo].title = "always the same"){ var bar = links[foo].href; //this should get your href alert(bar); } } Cheers, LC

Categories : Java

Regular expression to extract text from XML-ish data using GNU sed
I think you're much better off using a command line XML tool such as XMLStarlet. That will integrate well with the shell and let you perform XPath searches. It's XML-aware so it'll handle character encodings, whitespace correctly etc.

Categories : Regex

Regular Expression Select text between spaces
Just include the constant stuff you don't want to match in the pattern: @".*<OPERATE MODE> - (?'Recipe'.*?)s+Current User" Note that you need to make the repetition inside the group ungreedy, otherwise it will consume some of the spaces.

Categories : Dotnet

Ruby: Using a regular expression to find and open a file based on its filename?
File is for reading one file. You need to use Dir to find files by name. files = Dir['*'].select {|x| x =~ /_.*(css|scss|sass)/ } If you just want the last file in the case of dups: files = Dir['*'].select {|x| x =~ /_.*(css|scss|sass)/ }.sort.last

Categories : Ruby On Rails

Actionscript - syntax error creating regular expression to find image url
No. This is not valid regex: /(http(s?):)|([/|.|w|s])*.(?:jpg|gif|png)/gi ^ you need to escape this like this / because it is used as a delimiter in the regular expression.

Categories : Regex

How to replace part of a text using regular expression in JavaScript?
This pattern: /[^&]{0,}/ is gobbling up everything that is not a & character, which is why it extends beyond the URL itself. Instead, since you know that the width and height are numbers, you can just match on digits: .replace(/width=d*/gi,'width=300') .replace(/&height=d*|height=d*&?/gi,''); The  is a zero-width match to a word boundary, so that if you have framewidth=500 for example it won't be affected. The 2 matches to height are so that it won't replace both &'s if they are on each side. E.g. you don't want '?width=500&height=500&cache=123' to turn into '?width=300cache=123' for instance.

Categories : Javascript

Limit number of lines in text by a regular expression
I don't see why this would need any kind of lookaround. Just match only lines that contain foo: (?: ?[^ ]*foo[^ ]*){3} Notice that with the optional this might as well match a line that contains foo three times. To avoid that, use (?:(?:^| )[^ ]*foo[^ ]*){3} // or (?:[^ ]*foo[^ ]*(?: |$)){3} (depending on your regex flavour you might use different anchors for string beginning/end) If you need foo standing on it's own, just add word boundaries to it: (?: ?[^ ]*foo[^ ]*){3}

Categories : Regex

Sublime Text - Regular Expression for search and replace
Change your regex so that the .+ becomes lazy: \cite[(.+?)]{(.+?)} ^ ^ Making a greedy quantifier lazy means that instead of matching as much as possible, it will match as little as possible. In your current regex, the . will match all the characters until it finds another ) (followed by the other characters in the regex). Or use negated classes: \cite[([^]]+)]{([^}]+)}

Categories : Regex

How to write a regular expression to get text inside XML tags?
This expression will capture the address value <address>(.*?)</address> and place it into the first capture group Example Sample Text <name>Joe Blog</name> <email>abc@sample.com</email> <address>123 sample st</address> Matches [0][0] = <address>123 sample st</address> [0][1] = 123 sample st However Most langages have a html parsing tool, for example you could do this in PHP by using: $dom = new DOMDocument(); $dom->loadHTML($your_html_here); $addresses= $dom->getElementsByTagName('address'); foreach($addresses as $address) { $address = $address->innertext; // do something }

Categories : Regex

How to use a regular expression inside TermDocumentMatrix for text mining?
I'm not sure that you can put regex in the dictionary function as it only accepts a character vector or a term-document matrix. The work-around I'd suggest is using regex to subset the terms in the term-document matrix, then do word counts: # What I would do instead tdm <- TermDocumentMatrix(crude, control = list(removePunctuation = TRUE)) # subset the tdm according to the criteria # this is where you can use regex crit <- grep("cru", tdm$dimnames$Terms) # have a look to see what you got inspect(tdm[crit]) A term-document matrix (2 terms, 20 documents) Non-/sparse entries: 10/30 Sparsity : 75% Maximal term length: 7 Weighting : term frequency (tf) Docs Terms 127 144 191 194 211 236 237 242 246 248 273 349 352 353 368

Categories : Regex

how to search about text between brackets using regular expression using java?
Assuming that you don't have any nested brackets and you want to ignore * after [ you can use for example groups like in this example String data="Request ECUReset for [*11 01]"; Matcher m=Pattern.compile("\[\*?(.*?)\]").matcher(data); while (m.find()){ System.out.println(m.group(1)); } Also if you know you have only one matching part you can use one-liner System.out.println(data.replaceAll(".*\[\*?(.*?)\].*", "$1"));

Categories : Java

Regular expression not stripping text from quoted reply
In your sample input, On.*?wrote does not match, because On ... wrote: spans two lines. I changed your code to substitute On.*wrote:s* to empty string. def format_mail_plain(value, from_address): value = re.compile(r'^On.*?wrote:s*', re.IGNORECASE | re.MULTILINE | re.DOTALL).sub('', value) res = [re.compile(r'From:s*' + re.escape(from_address), re.IGNORECASE), re.compile('<' + re.escape(from_address) + '>', re.IGNORECASE), re.compile(r'-+originals+message-+s*$', re.IGNORECASE), re.compile(r'^from:', re.IGNORECASE), re.compile(r'^>')] lines = filter(None, [line.rstrip() for line in value.split(' ')]) result = [] for line in lines: result.append(line) for reg_ex in res: if reg_ex.search(l

Categories : Python



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