w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
what is the following regular expression trying to match?
In tcl, strings grouped by double quotes ("") undergo substitution when evaluated. As you know, tcl understands the following substitutions: variable substututions: Any word that starts with the $ sign is substituted for its value. command substutution: Any group of words between [ and ] is treated as a statement and the first word is called as a command (function). escape substitution: Any backslash () is treated as an escape sequence and substituted accordingly. Therefore, the following code: regexp "hello[^\n]*06" $str is equivalent to: regexp {hello[^ ]*06} $str So it's trying to match the string that contains the word "hello" and "06" without any newlines between them.

Categories : Regex

Javascript regular expression numeric range
Your use of {[1-5]} is invalid. { and } indicate that the number of matches is between the two numbers contained within it (either parameter can be omitted), whilst [1-5] matches one character out of 1, 2, 3, 4 or 5. You need: text = text.replace(/(d{3})(d{3})(d{4})(d{1,5})/, "($1) $2-$3 x$4"); instead. For more information, see this QuickStart on repetition.

Categories : Javascript

Regular expression to match a whole word
Square brackets are meant for character class, and you're actually trying to match any one of: s, |, s (again), e, a, s (again), o and n. Use brackets instead for grouping: (s|season) or non-capturing group: (?:s|season)

Categories : Regex

Match a string in a csv using regular expression
The '+' symbol in a regular expression is a quantifier, it stands for "one or more" so you are using it wrong you don't need to concatenate if that is what you are trying. You also need to use the method matches.

Categories : Regex

Regular Expression - Match But Exclude?
Here's an easy way: string sampleText = "<i>This should be in italics</i> but this ¶ character needs to be removed"; string sPattern = "(</?i>)|[―&<>♫♪–‧₢₳-⅓⅟□¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶•¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕ×ØÙÚÛÜÝÞßàáãäåæçèéêëìíîïðñòóôö÷øùüýþÿŒœŠšŸŽžƒ˜-‰›¢€°]"; string replacePattern = "$1"; string text = Regex.Replace(sampleText, sPattern, replacePattern, RegexOptions.IgnoreCase); Console.WriteLine(text); // <i>This should be in italics</i> but this character needs to be removed But this will only work with <i> and </i> tags. You can expand that to other tags pretty easily (e.g. "(</?w+>)|..."

Categories : C#

Regular Expression to Match IP Subnet
You might try using a lookahead. Also, please escape the . characters—otherwise it would match any character: @"d{1,3}.d{1,3}.d{1,3}(?=.d{1,3})" This will match any string like 127.65.231 as long as it's followed by a string like .111.

Categories : C#

How does the regular expression "(aa)+1" match "aaaaaa"?
The + quantifier means "1 or more". The 1 refers to the captured group, which is the same thing the quantifier is referring to. So effectively, it's saying "group aa, 1 or more times, and then one more time". Which is the same as "2 or more times". So the regex might be clearer as this: /(aa){2,}/ Since aaaaaa is three sets of the aa group, the regex matches the string.

Categories : Regex

Regular Expression Match for Password
You should use different anchors, and you can use a negative lookahead assertion to make sure that other characters than digits are present: ^(?![0-9]*$)[a-zA-Z0-9!@#$%^&*+=(){}:;,'./?-]{6,20}$ Also, you don't need to escape (most) regex metacharacters within a character class as they don't have a special meaning there.

Categories : Asp Net

Regular expression match for &DaysAgo=3
Almost there: /^&DaysAgo=d+$/. You do not need to escape the ampersand in regex, but in your case, you forgot to put a slash infront of the letter d. @hek2mgl's comment also applies.

Categories : PHP

vim match errors out with regular expression (?:([^f])fe|([lr])f)$
Vim's regular expression dialect is slightly different from the more common POSIX regexps and Perl-compatible regexps. The ?: which is used for grouping without capturing the submatch is expressed in Vim as \%(...) (or v%(...) in very magic mode). Therefore, you have to use: if 'calf' =~ 'v%([^f])fe|([lr])f)$' (Note how I've switched to single quotes to avoid escaping the backslash.)

Categories : Vim

Need to match at least 3 of given patterns in Regular Expression
It might not be a good idea to use regex for password validation, but using lookaheads and the or operator | allows you to do this: ^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])|(?=.*[#$%=@!{},`~&*()'?.:;_|^/&#43;"-])(?=.*[a-z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[#$%=@!{},`~&*()'?.:;_|^/&#43;"-])(?=.*[0-9])|(?=.*[A-Z])(?=.*[a-z])(?=.*[#$%=@!{},`~&*()'?.:;_|^/&#43;"-])).{8,32}$ There are 4 parts in this regex: (?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]) Makes sure there's at least 1 lower alpha, 1 upper alpha and 1 number. (?=.*[#$%=@!{},`~&*()'?.:;_|^/&#43;"-])(?=.*[a-z])(?=.*[0-9]) Makes sure there's at least 1 special character, 1 upper alpha and 1 number. (?=.*[A-Z])(?=.*[#$%=@!{},`~&*()'?.:;_|^/&#43;"-])(?=.*[0-9]) Makes sure there's at least 1 upper alph

Categories : Regex

Can't match this regular expression in Javascript
. matches all characters. Force it to skip the closing parentheses: style = style.replace(/translate3d([^)]+)/,"asdf"); Trying it out: > var style = "translate(-50%, -50%) translate3d(3590px, 490px, 0px) rotateX(0deg) rotateY(0deg) rotateZ(0deg) scale(1)"; > style = style.replace(/translate3d([^)]+)/,"asdf"); 'translate(-50%, -50%) asdf rotateX(0deg) rotateY(0deg) rotateZ(0deg) scale(1)'

Categories : Javascript

Bash Regular Expression -- Can't seem to match s, S, etc
Perhaps S and s is not supported or that you can't place them around [ ]. Try to use this format instead: ^Disk[[:space:]]+/dev[^[:space:]]+:[[:space:]]+[^[:space:]]+ EDIT It seems you actually want to get the matching fields. I made the script simpler to this but I'm not sure if it's your intended output: #!/bin/bash regex='^Disk[[:space:]]+(/dev[^[:space:]]+):[[:space:]]+(.*)' while read line; do [[ $line =~ $regex ]] && echo "${BASH_REMATCH[1]} matches ${BASH_REMATCH[2]}." done < disks.txt Which produces /dev/sda matches 42.9GB. /dev/sdb matches 42.9GB.

Categories : Regex

regular expression to not match something in quotes
There are two ways to go about this: You can use negative lookarounds (information here) to try and assert that there is not a double quote before or after something you don't want stripped. The problem I have with this is that there is no indication of how far away from the quotes : or ( might be, and lookarounds cannot be of unknown length. What I like to do, is to "preserve" anything enclosed within double quotes, with the regex "[^"]+" within an array, and replacing them with a string (I use "THIS_IS_A_QUOTE"). After you have stored all your quotes in an array, strip all spaces, and finally restore all "THIS_IS_A_QUOTE" strings with the strings in the array.

Categories : Regex

Regular expression to match colon
If you only want to handle that specific type of format (i.e. "public partial class 'classname'"). Something like this would do it: class Program { static readonly Regex re = new Regex( @"^public partial class[^:]+$", RegexOptions.Compiled ); static string Replacement( string stringToReplace ) { return re.Replace( stringToReplace, match => match.Value + ": IEntity" ); } static void Main() { string newString = Replacement( "public partial class Client" ); Console.WriteLine( newString ); //output: "public partial class Client: IEntity" newString = Replacement( "public partial class Server" ); Console.WriteLine( newString ); //output: "public partial class Server: IEntity" newString = Replacement( "

Categories : C#

Why does this regular expression match the second item and not the first
Regexes start at the beginning. It sees the F, and tries to match it against the BAR option. This of course fails. It then tries the FOO BAR option, and that seems to work, so it runs with that to find out if it works. Sure enough, it does, and so the match is FOO BAR.

Categories : Regex

Regular Expression for set notation style range validators
If you choice to do it with a regex, you must describe all the possibilities separated with |. Here an example for the first range (you can easily add values for the other ranges): @"1.[5-9]|[23](?:.[0-9])?|4" But the most elegant way IMO, is to extract all numbers and test them as numeric after.

Categories : C#

Regular Expression to match C data type
Try: [a-zA-Z]+(([])+|(*)+)? The | operator means "OR." Then the + operator means "one or more of the previous." Therefore, the regex means "some letters, then optionally (one or more []s) OR (one or more *s)." Here is a JSFiddle.

Categories : Regex

Can't use regular expression to match exact string
The problem with your regex was that you have used "?" marker which toggles the greediness of the "+" in your regex, so your regex "sschk@@d+?" means "a string sschk@@ followed by 1 or more numbers, but match as less digits as possible". Removing "?" would mean "a string sschk@@ followed by 1 or more numbers (match as much digits as possible)" Your regex statement might look like this perhaps: sschk@@\d{6} and it would match a string "sschk@@" followed by exactly 6 digits. If you want to match the string "sschk@@" followed with variable length of digits, but not more than 6, you might use sschk@@\d{1,6}. If you need to match any number of digits after the string "sschk@@" then use sschk@@\d+

Categories : Regex

C# regular expression to match square brackets
This happens because the regex matches part of the string, and you haven't told it to force the entire string to match. Also, you can simplify your regex a lot (for example, you don't need all those capturing groups: string rex = @"^[0-9]{2}.[1-9][0-9]?.[1-9][0-9]?.[1-9][0-9]{0,4}(?:[[a-zA-Z]])?$"; The ^ and $ are anchors that match the start and end of the string. The error message you mentioned has to do with the fact that you need to escape the backslash, too, if you don't use a verbatim string. So a literal opening bracket can be matched in a regex as "[[]" or "\[" or @"[". The latter form is preferred.

Categories : Regex

Regular Expression: How to match using previous matches?
You can try this: (w)1{2}(?!1)w1{3} Break Up: (w) # Match a word character and capture in group 1 1{2} # Match group 1 twice, to make the same character thrice - `XXX` (?!1) # Make sure the character in group 1 is not ahead. (X is not ahead) w # Then match a word character. This is `A` 1{3} # Match the group 1 thrice - XXX

Categories : Python

Can a string be padded to match a regular expression?
Have you considered splitting the regex on path separators and only applying the portion of the regex that applies at the current depth of your search? This seems like a much more efficient way of proceeding.

Categories : Regex

PHP Regular Expression will not match accented characters
I think this might work for you: $pattern = '/^[0-9a-zá-úàü][0-9_a-zá-úàü]*$/i'; I ran the following code to test the pattern: $str = "patinação"; $pattern = '/^[0-9a-zá-úàü][0-9_a-zá-úàü]*$/i'; if (preg_match($pattern, $str, $matches)){ echo $matches[0];//output: patinação }

Categories : PHP

android regular expression to match an address
You might consider using something like so: [sa-zA-Z0-9\.n°/]*. That being said, that particular regular expression will also match an empty field. If you do not want this, simply replace the * (matches 0 or more repetitions of) with + (matches one or more repetitions of). The is a special character, which needs to be escaped, hence the extra infront of it. The . is also a special character which also needs to be escaped. So, in Java, you would need to use something like so: [\sa-zA-Z0-9\\.n°/]*

Categories : Android

Regular expression that match decimal places
$("#price").val().match(/^d+((.|,)d+)?$/); the above won't limit the number of decimal places to four, though. By the way, that's a comma and not a "colon" To match decimal places up to 4 only, use this $("#price").val().match(/^d+((.|,)d{1,4})?$/); should match 1 to four numbers after . or ,

Categories : Javascript

How to create a regular expression to match the last occurrence of something?
Greedy expressions are your friend. They will attempt to get everything they can... then backtrack when they can't. To this end you can prepend most expressions with ^.* which will try and match as much as possible from the beginning.. leaving the end to whatever you want to find. So if you want to capture just the end... try: ^.*[(.*?)] Let's break this down: ^ # start of string .* # as much as possible [ # opening square bracket (.*?) # capture the minimum possible (non-greedy) ] # closing square bracket

Categories : Javascript

Java regular expression word match
You need word boundaries for that: boolean foundMatch = false; Pattern regex = Pattern.compile("\b(?:UI|PRI|RET)\b"); Matcher regexMatcher = regex.matcher(subjectString); foundMatch = regexMatcher.find();

Categories : Java

Perl regular expression to match numerics
[...] is a character class. It can match only a single character. Regular expressions have no concepts of numbers - only of digit characters. What your regex is saying is Match a character from 0 to 1 (that is 0 or 1) or match a 0. So it only matches one binary digit. You could use if ($currentRowHeader =~ /BSC(?:[0-9]|10)|TOTAL/) { print "OK" } Note that the ?: is not necessary but is a good habit, as it suppresses unnecessary capturing and hence speeds up the operation.

Categories : Regex

Regular expression to match uri segment in javascript
> re = //(w+)(?:-(w[-w]+))?(?:.(html))?/ //(w+)(?:-(w[-w]+))?(?:.(html))?/ > "/123".match(re) ["/123", "123", undefined, undefined] > "/123-my-name".match(re) ["/123-my-name", "123", "my-name", undefined] > "/123.html".match(re) ["/123.html", "123", undefined, "html"] > "/123-my-name.html".match(re) ["/123-my-name.html", "123", "my-name", "html"] then, m = url.match(re) id = m[1] name = m[2] || default format = m[3] || default A more specific option (id = only digits, anchored): > re = /^/(d+)(?:-(w[-w]+))?(?:.(html))?$/ /^/(d+)(?:-(w[-w]+))?(?:.(html))?$/ > "/123-my-route/edit.html".match(re) null

Categories : Javascript

Can Regular Expression Match Texts Incrementally?
Don't use regex to parse xml..Use linq2xml.. You can use string.Join. XElement doc=XElement.Load("yourXml.xml"); var lst=doc.Elements("node") .Select(x=>x.Value); string text= string.Join("",lst); And the result would be aabbbcccd

Categories : Dotnet

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#

regular expression to match a character that can only appear once in a string?
You can try this pattern: ^[^*]**[^*]*$ Explanations: ^ begining of the string [^*]* all characters except * zero or more times * literal * [^*]* all characters except * zero or more times $ end of the string

Categories : Regex

regular expression pattern doesn't match
line.matches("@@title@@") means the whole line matches. Imagine it like this line.matches("^@@title@@$") And replaceAll won't throw exception if there is no match, so you can simply drop your check: String line = " <title>@@title@@</title>"; line = line.replaceAll("@@title@@", "Title");

Categories : Java

Regular expression match if there's non-alphabetical character at the end, or nothing?
Use word boundaries . They match whenever a word character (w) and a non-word character are adjacent: for (qw/two to tomorrow/) { say "$_ ", /(?:two|to|too)/ ? "matches" : "doesn't match"; } Output: two matches to matches tomorrow doesn't match Edit I changed the regex to /(?:two|to|too)/ per tobyink's suggestion. This is more readable than tw?oo? and more correct than tw?o+, and triggers the trie optimization, which transforms that part of the regex into a very efficient state machine.

Categories : Regex

regular expression to match repeated characters?
This seems to work for me: /^(.)1*$/ The ^ character matches the beginning of the string, and the $ matches the end. The whole expression can be translated into: "At the beginning of the string, match any character, followed by any number of that same character, followed by the end of the string.

Categories : Regex

Using Regular expression to match Multiple choice?
"1. Any Text _ Goes here, And end with ? Or ." can translate to this in regex: d+.[^?.]*[?.] Does that work for you? This assumes you never have any question marks or periods within the question until the end... but that's sort of what you implied as well. Edit: Since you want the answers and not just the question itself and you are looking to distinguish between other types of questions, try this: ([ ]*d+.[^ ]+ (?:[ ]*[a-zA-Z])[^ ]+ )+[s]*Ans:[^ ]*) Edit live on Debuggex

Categories : Regex

Regular expression to match and replace "${foo}" but not "" in Java
I believe you're probably trying to edit your JSPs in a text editor that supports find by regex feature. Trying to parse your JSPs otherwise (like @fge pointed) wouldn't be wise though. Here's a regex that would match ${foo} but not ="${foo}" (?<!=")${foo}(?!") effectively eliminating a match on <c:if test="${foo}" /> or <c:when test="${foo}" />

Categories : Java

Regular Expression issue in C# returning match true
The problem is that all parts of your regex are optional, that means that even an empty string will match your regex. Even if some invalid string were passed in, it would still match a zero-length substring at the start of the input. Also, you've escaped the slashes. This is not necessary in a verbatim string literal (a string literal starting with @). The string regular string literal "foo\bar" is equivalent to to the verbatim literal @"fooar" . I think you'll want to add start (^) and end ($) anchors to your pattern: new Regex(@"^(([a-zA-Z][0-9a-zA-Z+-.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$.-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$.-_!~*'()%]+)?$"); This will make ^ fail, but an empty string still matches (since all parts are still optional) and $ is still valid input. It's hard to tell e

Categories : C#

Simple regular expression for digit and word match
preg_match('/Something-[0-9]+/', $msg, $matches); If you wanted five characters specifically, preg_match('/Something-[0-9]{5}/', $msg, $matches);

Categories : PHP

Erlang regular expression must match entire string
Just add a $ on the end to match the full line: ^([a-zA-Z0-9]{1,50}:[^:][ ]?[a-zA-Z0-9.-\_+]{1,50})$ ^ here This is a feature of regular expressions, not Erlang specifically.

Categories : Regex



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