w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
matching an address with regex doesn't match the target part
Try d+s+(D+)d+D*$ D means 'anything that is not d, so it won't be allowed to match, for example, between the first 1 and 4, because then the ending of the regex would be rejected at the later 5.

Categories : Ruby On Rails

Find all lines that match regex pattern and grab part of string
You can do something like this(no need of regex): Use str.startswith to check if a line starts with '\': >>> strs = "\BTLCMOODY01 MRA Server " >>> strs.startswith('\') True Then use a combination of str.split and str.lstrip to get the first word: >>> strs.split(None, 1) ['\BTLCMOODY01', 'MRA Server '] #apply str.lstrip on the first item >>> strs.split(None, 1)[0].lstrip('\') 'BTLCMOODY01' Code: >>> with open('abc1') as f: ... for line in f: ... if line.startswith('\'): #check if the line startswith `` ... print line.split(None,1)[0].lstrip('\') ... TESTHOSTDEV01 TESTHOSTDEVDB01 TESTHOSTDEVDBQA TESTHOSTDEVQA02 BTLCMOODY01 BTLCSTG05 BTLCWEB02 BTLCWSUS01 HIMSAPP01 SLVAPP01 TORAAPP01 HNSVA

Categories : Python

Regex in Java to match a word that is not part of other word
Why not use word boundary? Pattern pattern = Pattern.compile("\bname\b"); String test = "name (name) mynames"; Matcher matcher = pattern.matcher(test); while (matcher.find()) { System.out.println(matcher.group() + " found between indexes: " + matcher.start() + " and " + matcher.end()); } Output: name found between indexes: 0 and 4 name found between indexes: 6 and 10

Categories : Java

Regex for finding matching on one part of a String and not another part
Using ^ for negation only works in character classes. You need a lookahead. The easiest way is to look from the beginning of the string (^) all the way through for appendCsrfToken with a negated lookahead. If that works, then go ahead and match the do?: ^(?!.*appendCsrfToken).*(.do?w) Demo.

Categories : Java

Regex to match paths that don't match a specific pattern: Express Router
The following regex will match any path except those starting with /foo/ app.get(/^/([^f][^o][^o]|.{1,2}|.{4,})/.*$/, routes.index); I assume that this is a standard javascript regex.

Categories : Regex

Regex to match single new line. Regex to match double new line
To match exactly N repetitions of the same character you need lookaheads and lookbehinds (see Match exactly N repetitions of the same character). Since javascript doesn't support the latter, a pure regexp solution seems to be impossible. You'll have to use a helper function, for example: > x = "...a...aa...aaa...aaaa...a...aa" "...a...aa...aaa...aaaa...a...aa" > x.replace(/a+/g, function($0) { return $0.length == 2 ? '@@' : $0; }) "...a...@@...aaa...aaaa...a...@@"

Categories : Javascript

Regex to match only till first occurence of class match
You were missing ? Your regex would be (?i)(.*?)case[^a-zd]*(d+)(.*) You can toggle case insensitive match using (?i) in regex

Categories : Regex

Regex that match if the match contains special word
You're kind of on the right track with lookahead assertions: {{START}}(?:(?!{{END}})[sS])*specialword(?:(?!{{END}})[sS])*{{END}} Explanation: {{START}} # Match {{START}} (?: # Match... (?!{{END}}) # ...as long as we haven't reached {{END}} yet: [sS] # any character )* # any number of times. specialword # Match "specialword" (?: # Match (as before)... (?!{{END}}) # whatever follows, unless it's {{END}} [sS] )* {{END}} # Then finally match {{END}}

Categories : Regex

Regex - Find the match that is inside a match
You can try this regex: /href=[^>]+.pdf/ regex101 demo Most of the time, when you can avoid .* or .+ (or their lazy versions), it's better :) Also, don't forget to escape periods.

Categories : PHP

Java regex: need one regex to match all the formats specified
Try using a reluctant quantifier: _year:.*?s. .replaceAll("_year:.*?\s", "_year:Y ") System.out .println("utc-hour_of_year:2013-07-30T17 dsfsdgfsgf utc-week_of_year:2013-W31 dsfsdgfsdgf" .replaceAll("_year:.*?\s", "_year:Y ")); utc-hour_of_year:Y dsfsdgfsgf utc-week_of_year:Y dsfsdgfsdgf

Categories : Java

Regex.Match() won't match a substring
Try removing ^ and $: Regex regex = new Regex(@"[ABCEGHJKLMNPRSTVXY]{1}d{1}[A-Z]{1} *d{1}[A-Z]{1}d{1}", RegexOptions.None); ^ : The match must start at the beginning of the string or line. $ : The match must occur at the end of the string or before at the end of the line or string. If you want to match only in word boundaries you can use  as suggested by Mike Strobel: Regex regex = new Regex(@"[ABCEGHJKLMNPRSTVXY]{1}d{1}[A-Z]{1} *d{1}[A-Z]{1}d{1}", RegexOptions.None);

Categories : C#

regex not returning match but there is clearly a match
You need to escape the dollar sign. start = '>$' end = '</td>' AnnualDiv = re.search('%s(.*)%s' % (start, end), s).group(1) The reason is that the $ is a special character in regex. (It matches the end of a string or before the newline.) This will set AnnualDiv to the string '0.48'. If you want to add the $, you can do it using this: AnnualDiv = "$%s" % re.search('%s(.*)%s' % (start, end), s).group(1)

Categories : Python

Javascript regex to match a regex
A regular expression to match a regular expression is //((?![*+?])(?:[^ [/\]|\.|[(?:[^ ]\]|\.)*])+)/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/ To break it down, / matches a literal / (?![*+?]) is necessary because /* starts a comment, not a regular expression. [^ [/\] matches any non-escape sequence character and non-start of character group [...] matches a character group which can contain an un-escaped /. \. matches a prefix of an escape sequence + is necessary because // is a line comment, not a regular expression. (?:g...)? matches any combination of non-repeating regular expression flags. So ugly. This doesn't attempt to pair parentheses, or check that repetition modifiers are not applied to themselves, but filters out most of the other ways that regular expressions

Categories : Javascript

How to select only certain part in a match?
Try following code: > '/v/dkdkd-akdoa?'.replace(/(v/).+?/, '$1replace') "/v/replace" If you want keep ?: > '/v/dkdkd-akdoa?'.replace(/(v/).+(?=?)/, '$1replace') "/v/replace?" $1 reference the first group ((v/))

Categories : Javascript

How to match features only in a part two given images?
I would copy the "particular part of image 2" in another matrix, and use it for the detection / matching. For instance, if you wanted to create a matrix pointing to the region of "image2" defined by the first 5 columns and 10 rows, you could do: cv::Mat subMatrix = image2.colRange(0, 5).rowRange(0, 10); And then you would use subMatrix for the matching.

Categories : Opencv

How can I replace part of a Match in Regular expression
The problem is that the regex is consuming everything that is matched including the single letter. The way to do it is as follows: const string pattern = "(\w)</span>"; const string replace = "$1&nbsp;</span>"; What this does is capture the single letter match using the () and then putting it into the replaced string using $1. As pointed out by @dasblinkenlight you could also use non-capturing lookbehind as follows: const string pattern = "(?<=\w)</span>"; const string replace = "&nbsp;</span>"; The pattern here uses special syntax to say very roughly that the w must be there but is not part of the actual match. So this method is probably closer to what you want since it matches just the thing you want to replace. See http://msdn.microsoft.com/en

Categories : C#

How to match part of rows in different tables with each other in MySQL?
Join the two tables with the following JOIN condition: ON ( country.tld = RIGHT(urls.domain, CHAR_LENGTH(tld)) ) Notice this query couldn't use an index on urls.domain, if such an index exists. I would precompute the top-level domain of urls.domain on insertion in a separate column (in urls). Set an index on this new column, and use this column in your JOIN condition.

Categories : Mysql

substring regex for first part of url
try this: select substring('https://dev.foo.com/bar/action/?param=val' from '(https?://([^/]*/){1,2})'); template1=# select substring('https://dev.foo.com/bar/action/?param=val' from '(https?://([^/]*/){1,2})'); substring ------------------------- https://dev.foo.com/bar/ (1 row) template1=# select substring('http://dev.foo.com/bar/action/?param=val' from '(https?://([^/]*/){1,2})'); substring ------------------------ http://dev.foo.com/bar/

Categories : Regex

Regex matches only part of a URL - why?
To answer your question why the regex doesn't work: It doesn't observe Java's regex syntax rules. Specifically: [^[:punct:]s] doesn't work as you expect it to because Java doesn't recognize POSIX shorthands like [:punct:]. Instead, it treats that as a nested character class. That again leads to the ^ becoming illegal in that context, so Java ignores it, leaving you with a character class that matches the same as [:puncts] which only matches the c of com, therefore ending your match there. As for your question of how to find URLs in a block of text, I suggest you read Jan Goyvaert's excellent blog entry Detecting URLs in a block of text. You'll need to decide yourself how sensitive and how specific you want to make your regex. For example, the solution proposed at the end of the

Categories : Java

Looking for non-zero property TOs: Can I match a Description with number property, but use a regex match?
It is known that integer types has to be passed as integers in the description rendering the usage of regular expressions useless unfortunately. I do not have a QTP installation at hand right now, but to investigate it further, what happens if you use Print Browser("myBrowser").WebElement("height:=11").ChildObjects.Count and Print Browser("myBrowser").WebElement("height:=^[1-9][0-9]*$").ChildObjects.Count Where "myBrowser" is your browser definition of course.

Categories : Regex

Replace part of lines of a file that match a string in Bash
You could actually do that with one sed (if it supports -r): sed -rie '/3199|26543/s/^(.{7}).*/1 0; 0;/' inv.txt With the arrays: #!/bin/bash removing=(3199 26543) ( IFS='|'; sed -rie "/${removing[*]}/s/^(.{7}).*/\1\t0;\t0;/" inv.txt; )

Categories : Bash

Return the part of the regex that matched
Very simply, no. Regex matches have to do with your input string and not the text used to create the regular expression. Note that that text might well be lost, and theoretically is not even necessary. An equivalent matcher could be built out of something like this: var test = function(str) { var text = str.toLowerCase(); return text === "horse" || text === "camel" || text === "tortoise"; }; Another way to think of it is that the compilation of regular expressions can divorce the logic of the function from their textual representation. It's one-directional. Sorry.

Categories : Javascript

Return part of string using Regex
Don't use a regex for this. Assuming you're using C#.NET, use the static ParseQueryString() method of the System.Web.HttpUtility class that returns a NameValueCollection. Uri myUri = new Uri("http://www.example.com?GetUploadedUserAudioIdfriendlyName=eb0c5663-a9c3-4321-8c0e-5ffbfb3139fc"); string param1 = HttpUtility.ParseQueryString(myUri.Query).Get("param1"); Check this documentation EDIT: If you want it as a Guid after that, then cast it to one: var paramGuid = new Guid(param1);

Categories : Regex

Replace part of a string using regex in VB.NET
You could just do this: Dim nameEnd as String = namePara.Remove(namePara.Length - 3) & "END" But if you must use Regex: Dim nameEnd as String = Regex.Replace(namePara, "STA$", "END")

Categories : Regex

replacing part of regex matches
To transform get_num(...) to get_num_struct(...), you need to capture the correct text in the input. And, you can't put the parentheses in the regular expression because you may need to match pointers to functions too, as in &get_distance, and uses in comments. However, and this depends partially on the fact that you are using vim and partially on how you need to keep the entire input together, I have checked that this works: %s/get_w+/&_struct/g On every line, find every expression starting with get_ and continuing with at least one letter, number, or underscore, and replace it with the entire matched string followed by _struct. Darn it; I shouldn't answer these things on spec. Note that other regex engines might use & instead of &. This depends on having magic set

Categories : Vim

PHP Regex for rewriting part of URL in 404 script
If all your URL are based like that, don't use preg_match but explode which is faster and easier to use : <?php // ... $explodedUrl = explode('-', 'oldnonexistentcategory-actualproduct-product_reviews-actualproduct.htm'); $redirectUrl = $explodedUrl[2].'-'.$explodedUrl[3]; echo $redirectUrl; // product_reviews-actualproduct.htm But be careful, this suppose 2 things : Your URL are always based on 4 parts, separated by "-": "string-string-string-string.htm" A part of the slug "string" can't have a "-" char (Otherwise, the script will not work corretly). So make sure you don't have a slug with "-" char in a part, not like that : old-non-existent-category-actual-product-product-reviews-actual-product.htm If your URL can have more or less than 4 parts, and you always want

Categories : PHP

Selecting part of a field with a regex
No, sad to say MySQL doesn't have a way to apply a regex to a column's contents in a SELECT clause, only a WHERE clause. But you can use ordinary (non-regex) string manipulation functions to do this. If the column containing your ampersand-separated parameter string is named url, you can get the id number with this fine string expression, which finds your id number. CAST(RIGHT(url, LENGTH(url) - 3 - LOCATE('&id=', url)) AS SIGNED INTEGER) So, if you want a list of id values from the url columns of table1, you could use this SELECT query. SELECT CAST(RIGHT(url, LENGTH(url) - 3 - LOCATE('&id=', url)) AS SIGNED INTEGER) AS id FROM table1 WHERE url REGEXP '&id=[0-9]+' As you can see this uses the regexp search function to locate the appropriate r

Categories : Mysql

How to make the last part of this REGEX optional?
Use ? quantifier, which makes your pattern optional. It matches either 0 or 1 occurrence of the pattern. Also, you need to group the last slash, with your last part of your regex, in a non-capturing group. ([^/]+)/([0-9]+)(?:/([^/]+))?

Categories : Javascript

Python parentheses and returning only certain part of regex
Your example code seems fine already, but to answer your question, you can make a non-capturing group using the (?:) syntax, e.g.: set(d+)(?:e|x) Additionally, in this specific example you can just use a character class: set(d+)[ex]

Categories : Python

RegEx for string getting words without spaces, but one part could have them
You could split it into the parts in one line: String[] parts = str.split("(?<!Leather|Steel|Wood(en)?|Glass|Iron|Bronze) (of )?"); You can add as many adjectives as you need. This uses a negative look-behind to assert that the space being split on is not preceded by an adjective. The optional (of )? consumes the "of" between terms. Here's a test: String str = "Windwalkers angry Leather Claws of Destruction"; String[] parts = str.split("(?<!Leather|Steel|Wood(en)?|Glass|Iron|Bronze) (of )?"); System.out.println(Arrays.toString(parts)); Output: [Windwalkers, angry, Leather Claws, Destruction]

Categories : Java

Extracting a specific part of a URL using regex in JavaScript
no need for regex, just split it var link = "http://www.test.com/abc/hhhhhh/a458/example"; var linkParts = link.split("/"); //If the link is always in that format then a458 or whatever //would replace it will be in index 5 console.log(linkParts[5]);

Categories : Javascript

Use regex to retrive a certian part of a string
Use the below regex. regex = src.match(/.images.*/i); console.log(regex[0]); Check this fiddle Demo EDIT Actually the dot at the start in the regex would match any character, so you could even replace that with the forward slash for this case. (forward slash is a special char, so escaped with a backward slash) regex = src.match(//images.*/i);

Categories : Javascript

regex for url in image tag with unknown part in the middle using PHP
The regex should be /oldPath(.*?)old filename/ and the replacement would be newPath$1newFilename. I.e. preg_replace('/oldpath(.*?)oldfilename/', 'newpath$1newfilename', originalHTMLstring);

Categories : PHP

Replacing part of delimited string with R's regex
Perhaps something like this: > gsub("([A-Za-z]+-)([A-Za-z]+-)(.*)", "\1\2zzz", name) [1] "hsa-miR-zzz" "hsa-miR-zzz" "hsa-let-zzz" There are actually several ways to approach this, depending on how "regular" your expressions actually are. For example, do they all start with "hsa-"? What are the options for the "middle" group? Might there be more than three dashes?

Categories : Regex

Using regex to get the text of a string but excluding the last part?
.*(?=sins<span) Will match anything before an in span on the line. Demo: http://rubular.com/r/bXitHsTPuB

Categories : Ruby

Replace part of string between quotes in php regex
Description I would attack this problem by first splitting the string into groups of either quoted or not quoted strings. Then iterating through the matches and if Capture Group 1 is populated, then that string is quoted so just do a simple replace on replace Capture Group 0. If Capture group 1 is not populated then skip to the next match. On each iteration, you'd want to simply build up a new string. Since splitting the string is the difficult part, I'd use this regex: ("[^"]*")|[^"]* Example Sample Text "mission podcast" modcast A B C "D E F" Code PHP Code Example: <?php $sourcestring="your source string"; preg_match_all('/("[^"]*")|[^"]*/i',$sourcestring,$matches); echo "<pre>".print_r($matches,true); ?> Capture Groups $matches Array: ( [0] => Array

Categories : PHP

Grabbing a part of a string using regex in python 3.x
Do you mean something like this? >>> import re >>> a = "I am a programmer" >>> reg = re.compile(r'I am (.*?)$') >>> print('How long have you been {}'.format(*reg.findall(a))) How long have you been a programmer r'I am (.*?)$' matches I am and then everything else to the end of the string. To match one word after, you can do: >>> a = "I am an apple" >>> reg = re.compile(r'I am (w+).*?$') >>> print('How long have you been {}'.format(*reg.findall(a))) How long have you been an

Categories : Python

JavaScript replace part of string regex
Yes, it is about regex. You can learn them here Your code will look like this: name.replace(/item-name-(.*)/, 'item-name-newone');

Categories : Javascript

Regex, target a char, but not if it a part of certain word
Try using word boundaries: Regex pattern = new Regex(@"x"); Also, the @ avoids you the task of double escaping. A word boundary is a special character which will match between a letter, digit or underscore and a non-letter/non-digit/non-underscore. Basically, if you have aa,  will match only at the start and end, not in the middle. If you have a.2c,  will match before a, between a and the ., between . and 2, and after c, but not between 2 and c. You can get more info on this site. Also, if you want to get an x which is in brackets, you can use lookarounds: Regex pattern = new Regex(@"(?<=()x(?=))"); (?<=() is a positive lookbehind and checks to make sure there's an opening paren before x. (?=)) is a positive lookahead and checks to make sure there's a closing paren aft

Categories : C#

Regex .* expression extracts only a part of the characters I want to extract?
The square brackets make the entire match a character class This expression will match Mike Tyson (?<=rder=3D"0" width=3D"650">=0D=0A <tr>=0D=0A <td valign=3D"top">=0D=0A <p>=0D=0A <strong>Hi ).*?(?=</strong>,<br/>=0D=0A =) Live Example: http://www.rubular.com/r/OaK2ZmbSPh

Categories : Ruby



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