w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
URL rewriting Regex with capture group
(?:/PeopleDirectory(?:/|))(.*) with replace /Explorer/PeopleDirectoryProxy.aspx?pdurl=$1 only 1 thing the .aspx will be used as a parameter you can exclude it in some way or i must exclude via regular expression?

Categories : Dotnet

Why does this regex named group capture the wrong text?
Use MatchData#[] to get specific group string: str1 = <<eos Burp FirstName: Al Bundy Ref person: Some address: loststreet 4 Some other address: loststreet 4 Zip code: eos regex1 = /FirstName:s?(?<name>[^ ]*).*Ref person:s?(?<ref_id>[^ ]*).*Some other address: (?<other>[^ ]*)/mi matched = str1.match(regex1) matched['name'] # => "Al Bundy" matched['other'] # => "loststreet 4"

Categories : Ruby

.NET Regex to back capture only the number from a matching group
I do not think this is possible - here's a question that seems to be exactly the same thing you're asking for: Regex Pattern Matching Concatenation

Categories : Dotnet

Accessing my capture group in regex pattern matching in Expect to a variable
The issue is that you are including line anchors ^ and $ in your regex. The string you're trying to match is clearly a multi-line string, but Tcl's default matching treats newlines just like a regular character. Another complicating factor is that Tcl considers a newline to be but expect is using as the line terminator. If you enable newline sensitive matching in the regular expression and take the carriage return into account, you may find this regular expression works: (?n)^thississasline((?:sd)+) ?$ Testing: $ expect <<END spawn sh -c {echo foo; echo "this is a line 2 4 5 6"; echo bar} exp_internal 1 expect -re {(?n)^thississasline((?:sd)+) ?$} END spawn sh -c echo foo; echo "this is a line 2 4 5 6"; echo bar Gate keeper glob pattern for '(?n)^thississasline((?:sd)+) ?

Categories : Regex

How do you reference a capture group with regex find and replace in Visual Studio 2012
To find and replace in VS 2012 you do the following: Surround with (), display capture with $1, $2, $n Example (thanks to syonip) In the find options, make sure 'use regular expressions' is checked, and put the following as the text to find: _platformActions.InstallApp((.+)) And the following as the text to replace it with: this.Platform().App($1).Install() Note: As SLaks points out in a comment below, the change in regex syntax is due to VS2012 switching to the standard .Net regex engine.

Categories : Visual Studio

perl regex: stucked with regex capture
Sections like this if (defined $reply[$count]) { ($Reply{$Log_name}) = $reply[$count] =~ /Time for unzip reply=(d+) s./; printf "$Reply{$Log_name} "; } Become if (defined $reply[$count] && ($reply[$count] =~ /Time for unzip reply=(d+) s./) ) { ($Reply{$Log_name}) = $1 print "$1 "; } I assume some of your data matches /Time for unzip reply/ but not /Time for unzip reply=(d+) s./

Categories : Regex

Capture a group in RewriteCond
You need to use the % backreferences: RewriteCond %{QUERY_STRING} size=(d+) RewriteCond ^ /%1 [L] The %1 backreferences a previously captured group in a rewrite cond.

Categories : Htaccess

Expected outcome in group capture?
The .* is matching (and consuming) as much characters as it can before finding \d+. When it gets to \d+, only one number is enough for matching. So, you need to make the .* lazy: (.*?)(\d+)(.*) Well, if you want to go into the details, .* first matches the whole string, then backtracks one character at a time so that the regex can also match (\d+)(.*) which comes later on. Once it has backtracked to the last character here: This order was placed for QT300 The rest of the regex ((\d+)(.*)) is satisfied so the matching ends.

Categories : Java

Do the following capture group notation mean something to Perl
Actually Perl is interpreting 111 as an octal, which is not found in your string. It would only consider two or more digits backreferences if such number of groups is found. To avoid the ambiguity, use g or g{}. Quoting the docs (perlre - Capture Groups): The g and k notations were introduced in Perl 5.10.0. Prior to that there were no named nor relative numbered capture groups. Absolute numbered groups were referred to using 1 , 2 , etc., and this notation is still accepted (and likely always will be). But it leads to some ambiguities if there are more than 9 capture groups, as 10 could mean either the tenth capture group, or the character whose ordinal in octal is 010 (a backspace in ASCII). Perl resolves this ambiguity by interpreting 10 as a b

Categories : Regex

PHP regex, how can I make my regex only return one group?
preg_match_all is returning exactly what is supposed to. The first element is the entire string that matched the regex. Every other element are the capture groups. If you just want the the capture group, then just ignore the 1st element. preg_match_all('/hello:"(.*?)"}/', 'hello:"abcdefg"},"other stuff', $arr, PREG_PATTERN_ORDER); $firstMatch = $arr[1];

Categories : PHP

when using pattern matching in Lua with paranthesis, how does one use "%2" to get the capture group
That pattern was designed to keep only the forward part of each line. Here's how it does that. The second parenthesis, ( [^ =]+=), captures the first substring of the form " stuff=". Then the %2 at the end of the pattern will only match if that same, string, " stuff=" appears again. So on a line like ipv4 2 tcp 6 3598 ESTABLISHED src=192.168.1.117 dst=137.194.2.78 sport=59078 dport=80 packets=4 bytes=298 src=137.194.2.78 dst=132.227.127.212 sport=80 dport=59078 packets=3 bytes=567 [ASSURED] mark=0 use=2 the second capture will be " src=", so the first capture, which is what is assigned to line, will be the whole initial portion of the line until just before the second time src= appears, that is, this initial part: ipv4 2 tcp 6 3598 ESTABLISHED src=192.168.1.117 dst=13

Categories : Json

Escaping regX in capture group java
if the one you gave was working for you then this one should work fine (?<=").*((?:")[^"]*(?:")|-).*(?=") in this I have used the look ahead and behind they will match the " in the starting and end but won't include it in the answer.

Categories : Java

Capture $ in regex Python
The question mark at the start is the cause of the nothing to repeat error. >>> import re >>> re.compile(r'?') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/mj/Development/venvs/stackoverflow-2.7/lib/python2.7/re.py", line 190, in compile return _compile(pattern, flags) File "/Users/mj/Development/venvs/stackoverflow-2.7/lib/python2.7/re.py", line 242, in _compile raise error, v # invalid expression sre_constants.error: nothing to repeat Match the dollar plus digits and dots: r'$[d.]+' Demo: >>> re.search(r'$[d.]+', 'blah blah blah (blah $23.32 blah) blah blac (blah)').group() '$23.32'

Categories : Python

C++11 Regex Capture Groups By Name
You cannot name a capture group with the c++11 standard. C++11 regex conforms to the ECMAScript syntax. Here is a link that explains it all http://www.cplusplus.com/reference/regex/ECMAScript/. Even though this maybe disappointing if you think about it a true regular expression will not support this it is extra.

Categories : Regex

Removing singleton dimension of scan capture group
Array#flatten may help foo = "bar = everybody bar = say bar = hey bar = ho" foo.scan(/^bar = (.*)$/).flatten #=> ["everybody", "say", "hey", "ho"]

Categories : Ruby

Regex capture first/last word in a filename
Description This expression will: assumes the only interesting data from the file name exists before the first dot assumes the initials are three upper case, preceeded by a space, and will be followed by a dot capture the non initials and non date portion of the file name capture the entire file name upto but not including the first dot capture the initials if they exist capture the date if it exists allow date, initials and file to appear in any order if they exist in the filename For this I'm using the ^ (?=(?:[^.]*?(?<file>(?<=^)[a-zA-Zs]*?(?=s[A-Z]{3}.|s)|(?<=s)[a-zA-Zs]*?(?=.|s[A-Z]{3}.)))?) # get the file (aka not date and not initials (?=(?:[^.]*?s(?<Initials>[A-Z]{3}).)?) # get the initials (?=(?:[^.]*?(?<Date>d+))?) # capture the date value

Categories : C#

use a regex capture in a pgSQL select
Using a subselect and the substring method you should be able to achieve what you want like so: SELECT * FROM firstTable WHERE parentCat = (SELECT cat FROM secondTable WHERE cat in substring(column_to_capture_from from 'thomas-var-3="(.+?)' )); from http://www.regular-expressions.info/postgresql.html If there is a match, and the regex has one or more capturing groups, the text matched by the first capturing group is returned.

Categories : SQL

regex to capture any several words in a sentence
Here's a regex that matches 1 to 3 words between the words "key" and "has", and here's a link to a RegExr that tests it. I admit I'm not familiar with spamassassin but if all you need it a regex to match a line of text then this should work: key(s((w+s){1,3})has Using the braces {1,3} means that the previous token (in this case, the group (w+s)) must match at least once but no more than three times. The  token matches a word boundary, and s matches any whitespace. w, as you know, matches any alphanumeric character. If you need to, you can use backreferencing to extract group 1, which now contains the words between "key" and "has" (as well as the whitespace surrounding them). Hope this helps!

Categories : Regex

Regex: set capture to fixed string
There is no way to get anything in to a capturing group which isn't in the input string. Capturing groups are (at least in Perl) partially represented as start/end positions of the original input string. If the value you want the capturing group to get is in the input string you can do that using lookarounds. The desired string has to be after the match if your regex flavor has a limited lookbehind (like PHP). For example: preg_match('/a(?=.*(?<id>b))/', 'a foo b', $matches); print "matched '$matches[0]', id is '$matches[id]'"; Output: matched 'a', id is 'b'

Categories : Regex

Regex capture value within bracket, value contain brackets as well
A pretty simple way would be as follows if I'm understanding you correctly: 1. iterate through characters 2. find first left brace 3. count braces until non-paired right brace appears and store index 4. take the substring from zero to that index and set as value x 5. delete value x substring 6. go to step 1 and store next part as value y

Categories : C#

Multiline regex capture in Scala
If you want to activate the dotall mode in scala, you must use (?s) instead of (?m) (?s) means the dot can match newlines (?m) means ^ and $ stand for begining and end of lines

Categories : Regex

Search-and-replace regex with capture
You could do it like this: #!/usr/bin/perl use strict; use warnings; my $text = 'lis r3, ha16(L_.str10) some more text blah lis r3, lo16(identifier) some more text blah lis r3, ot16(identifier)'; $text =~ s/(w{2})d{2}(([w.]+))/$1 eq 'lo' ? $2 . '@l' : $2 . '@' . $1/gie; print $text; Can also be written as: #!/usr/bin/perl use strict; use warnings; while (<DATA>) { s/(w{2})d{2}(([w.]+))/$1 eq 'lo' ? $2 . '@l' : $2 . '@' . $1/gie; #you can also print out the result of the replacement. #print $_; } __DATA__ lis r3, ha16(L_.str10) some more text blah lis r3, lo16(identifier) some more text blah lis r3, ot16(identifier) To put it simple the e modifier allows you to use code on the right hand of the regex that can be used to replace the pattern. For a more detail

Categories : Regex

Java Regex to capture several matches
I wouldn't use a regex for this. What about something along the lines of String[] split = s.split("/"); StringBuilder sb = new StringBuilder(s.lastIndexOf('/') + 1); // our result sb.append('/'); // initial "/" for (int i = 0; i < split.length - 1; i++) { // we don't care about the if (split[i].isEmpty()) // last component continue; sb.append(split[i]); sb.append('/'); System.out.println(sb); // or add to an array/list/etc. } /accounts/ /accounts/main/ /accounts/main/index/

Categories : Java

Regex to capture tags fails when "src" value is different
The * quantifier is greedy: it matches as much as it can while allowing the rest of the pattern to match. In your case, S* is likely consuming more text than you intended. Consider using my @accept = $message_body =~ /<img src="S*?">/gi; or my @accept = $message_body =~ /<img src="[^"]+">/gi; These patterns attempt to stop matching as soon as they detect a closing double-quote, but they are heuristics that could fail depending on how friendly your input is. To do the job properly, use an HTML parser.

Categories : Regex

Regex: how to capture new line only if certain criteria are met?
I am not sure how to tell regex "look for this in a new line, if it's there, capture the line. if it's not there, just stay on the current line. You could just match the new line as part of an expression repeated multiple times, e.g: d{3}( d{3})* Not sure of the specifics of exactly what you want to match but this is the best I could come up with without further info...

Categories : Regex

Regex to capture substring between quotes
By default, the * quantifier is "greedy", which means (.*) will match everything it possibly can. To restrict it such that it matches as little as possible, i.e. only until the next double-quote that occurs in the string, add a ? to it, thus: ($txid) = $content =~ m/<input name="transactionid" value="(.*?)" type="hidden">/; Assuming the value of the value attribute contains no escaped double quotes, this will produce the result you're after. (Of course, in cases where there are escaped double quotes, there is no regex which will reliably extract just the string of interest and nothing else. This is why people tell you not to use regexes as your sole tool for parsing balanced text. On the other hand, given the simplicity of your purpose here, you'll probably get away with it -- bu

Categories : Regex

RegEx to capture repeating fields?
I'm trying this in VB (because that's what I have open), but consider iterating the Capture for the group: For Each m As Capture In response.Match(example).Groups("Field").Captures Debug.WriteLine(m.Value) Next gives me ALPHAONE BETATWO CHARLIETHREE

Categories : C#

Does RegexPlanet support capture group references in the replacement string for .NET and, if so, how?
I can't entirely reproduce your problem. When using (...) capture groups, $1 works as a replacement string on regexplanet.com using the .NET engine. For named captures, though, you seem to be right - (?<foo>...) as named capture and ${foo} as its replacement don't work (I get a message saying ERROR: error ()).

Categories : Dotnet

Extract capture group matches from regular expressions? (or: where is gregexec?)
Not sure about doing this in base, but here's a package for your needs: library(stringr) str_match_all(s, r) #[[1]] # [,1] [,2] #[1,] "xy1234" "1234" #[2,] "xy567" "567" Actually I think stringr is just a wrapper on base functions, so you can fish out the base logic from the source if you want to. edit Here's a simplified version of how the above works: sapply(regmatches(s,gregexpr(r,s))[[1]], function(m) regmatches(m,regexec(r,m)))

Categories : Regex

Ruby - best way to extract regex capture groups?
For simple tasks, directly accessing the pseudo variables $1, etc. may be short and easier, but when things get complicated, accessing things via MatchData instances is (nearly) the only way to go. For example, suppose you are doing nested gsub: string1.gsub(regex1) do |string2| string2.gsub(regex2) do ... # Impossible/difficult to refer to match data of outer loop end end Within the inner loop, suppose you wanted to refer to a captured group of the outer gsub. Calling $1, $2, etc. would not give the right result because the last match data has changed by doing the inner gsub loop. This will be a source of bug. It is necessary to refer to captured groups via match data: string1.gsub(regex1) do |string2| m1 = $~ string2.gsub(regex2) do m2 = $~ ... # match data of t

Categories : Ruby

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 do I write a regex to match and capture at the same time?
What you are looking for is puts "line#{$1}". The pseudo-globals $1, $2, $3, etc. refer to capture groups of the last Regexp match. (And $~ refers to the MatchData itself, if you'd like to work with that.)

Categories : Ruby

Javascript Regex Pattern Capture - all possible combinations
this works for me var str='||1|| Jam Jam jambura jadu tu sikh jambura'; reg = /(?!||(d+)|||jambura).+?jambura/g; re = /(?![|]+)d+(?=[|]+)/ alert('page '+str.match(re)+': '+str.match(reg).length+' matches'); Try Fiddle the idea is to match ||d+|| first, then only jumbara. Actually, I spent half of a night to find a solution, so I don't remember why I started to use ?! here, but it works

Categories : Javascript

Grep regex to capture ip socket without port
Simply use awk and split in characters {, :, } and blanks. Then count fields: awk -F'[{:}[:blank:]]+' '{ print $9, $11 }' infile It yields: 10.20.21.106 10.20.21.27

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

regex capture bind parameters following a colon
You just need a "look behind": (?<=:)w+ A look behind asserts, but does not capture, what comes before the match. Note the the whole match (not group 1 as in your regex) is your target. Also notice the simplification: w means exactly [a-zA-Z0-9_] . See this regex running on rubular

Categories : Javascript

Regex for Finding a Suffix, but do not capture from Right to Left
Use lookahead, (?=), to find something but not capture it. .+(?=s+d{5}) You can see that this regex works using this online tool.

Categories : Dotnet

capture content in html comments with regex
I guess you can make use of a positive lookahead: <!-- #BeginEditable "(Title|Text|Foo)" -->(.*?)(?=<!-- #EndEditable -->) Here's a demo on rubular. Note I used the m modifier to make the dots match newlines. The dot will thus match every character until it finds <!-- #EndEditable --> ahead.

Categories : HTML

Performing regex capture and then substitute using SED/PERL
You can use escaped parenthesis to capture groups, and access the groups with 1, 2, etc. sed 's/^(.*).txt$/perl mycode.pl /home/neversaint/1.txt > /home/neversaint/1.output/' submit.sh output: perl mycode.pl /home/neversaint/dir1/pmid_5409464.txt > /home/neversaint/dir1/pmid_5409464.output perl mycode.pl /home/neversaint/dir1/pmid_5788247.txt > /home/neversaint/dir1/pmid_5788247.output perl mycode.pl /home/neversaint/dir1/pmid_4971884.txt > /home/neversaint/dir1/pmid_4971884.output edit: it doesn't look like sed has a built-in in place file editing (GNU sed has the -i option). It still possible to do but this solution just prints to standard out. You could also use a Perl one liner as shown here: sed edit the file in place

Categories : Regex

Regex to capture characters at set positions in a variable string
It seems much easier to do this without using regular expressions, but for the sake of argument, you can use this pattern: ^(dd)(dd)?(dd)?$ Or this pattern, which actually has only one capture group, which might be easier to work with depending on your code: ^(dd){1,3}$ Both patterns will match either 2, 4, or 6 digits in groups of two and nothing else. Test it out here.

Categories : Regex



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