w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Boost regex not replacing expression that replaces correctly on regex websites
The problem come from your first (.+) which is greedy and grab all he can, probably until the last # of the subject string. You can try with this pattern: const char *scriptRegexFullNameReplace = "$1"$2"#"$3"$4"; scriptRegexFullName.assign("(\p{L}+,\d+,\d+,\d+\s+script\s+)([^#]+)#(\S+)(\s+\d+,\{)"); Notices: the escape of the curly bracket is probably uneeded, try to remove it. p{L} stand for any unicode letter but you can try replace it by [^,] if it is a problem You can replace all + by ++ for more performances (no backtracks allowed) No need to capture the sharp to replace it by itself, it is the reason why the pattern has only four capturing groups instead of using (.+?) (the dot with a lazy quantifier), it is better for performances to use a greedy quantifier with a reduced cha

Categories : C++

Parsing SQL statements with regex: Does adding the optional flag in a regex expression change how greedy or posessive modifiers are matched?
Parsing SQL with regex is not much different from parsing HTML with regex. In other words, it won't work. It is hopeless task, stop right now. Instead, use some SQL parser. For example, SQL::Statement::Structure for Perl or ANTLR for Java. Also, since you are creating your own database, it is worth taking a look at how other SQL implementations do it. I would recommend reading source code for PostgreSQL or MySQL and see how they implement advanced SQL parsing.

Categories : Java

Performing a Regex Expression on a String of which may contain Regex Metacharacters?
.NET provides the Regex.Escape method for exactly this purpose: Dim regDirs = New Func(Of String, Boolean)(Function(i) Regex.IsMatch(i, "[d]+[s]" & Regex.Escape(strName), RegexOptions.Compiled Or RegexOptions.IgnoreCase))

Categories : Regex

Within same regex expression , performing multiple regex operations
From your description it sounds like you need to use the backreference construct Backreference Construct :MSDN There are examples in the linked page. Using this you can refer to repeated occurrences of a substring within a string.

Categories : Regex

Need a Regex Expression in iOS, I have the expression like ^([a-zA-Z][a-zA-Z0-9]{8-32}[<>%*])$
How about: ^[A-Za-z][A-Za-z0-9]{7,31}$ This only allows characters A-Z, a-z, and the numbers 0-9, which automatically excludes spaces and special characters. The explanation: ^[A-Za-z] means that it must start with a letter, either A-Z or a-z. The ^ symbol indicates the start. [A-Za-z0-9]{7,31}$ means that after the first rule is satisfied, there must be between 7 and 31 characters that are numbers or letters, after which we must reach the end; the $ indicates the end. If you have other characters you want to allow, you can add them to the first set of brackets, just don't forget to escape anything that needs it (such as *). Also notice that I used {7,31} to indicate 7 to 31 repetitions with a comma, not a dash as you have in your sample code. This is the reason you get the U_REGEX

Categories : IOS

what is this regex expression doing here
It looks like it replaces every occurrence of '$&' with '$bar' in $foo. This is a typical way to implement a simple place-holder token syntax in data. The value returned by eval is the result of treating the value of $foo as if it were Perl source code. Assuming normal execution, eval will return the last expression evaluated in $foo (or the argument of a return statement if one is executed). Note that evaluating $foo may also have side effects (I/O, variable assignments, etc.). It's impossible to say more without knowing what's in $foo to start with.

Categories : Perl

Regex expression C# for HTML
remove the ^, because it means beginning of the line. Therefore it will always get the first span. More so because .* means (any characters at all). doing this the first match may stil be the output you have now, but the second match should be what you're after. Furthermore tools like regexbuddy and such are good for testing Regex's.

Categories : C#

is there an OR expression in regex for clojure?
I take it you mean that you wish to match strings with either &| or | and then, in the case of a match, check which case it was that matched? If so, you can do by matching with a regex in which & is optional -- as suggested by HamZa in a comment on the question -- and using re-find or capture groups to capture the matching part of the string which you can then examine: (re-find #"&?|" "asdf|adsf") ;= "|" (re-find #"&?|" "asdf&|asdf") ;= "&|" With capture groups (use peek to get at a vector's final element): (re-matches #".*[^&](&?|).*" "asdf&|asdf") ;= ["asdf&|asdf" "&|"]

Categories : Regex

the right regex expression in python
Seems like it's always the second to last term in the comma separated list? You can split and select the second to last, example: >>> myStr = '2ème vin, Pessac-Léognan, Blanc' >>> res = myStr.split(', ')[-2] Otherwise, if you want regex alone... I'll suggest this: >>> res = re.search(r'([^,]+),[^,]+$', myStr).group(1) And trim if necessary for spaces.

Categories : Python

regex in bash expression
For your first question, an alternative is this: [[ $temp_input =~ "[^"]*" ]] For your second question, you can do this: temp_input=abcba t=${temp_input//b} echo "$(( (${#temp_input} - ${#t}) / 1 )) b" Or for convenience place it on a function: function count_matches { local -i c1=${#1} c2=${#2} if [[ c2 -gt 0 && c1 -ge c2 ]]; then local t=${1//"$2"} echo "$(( (c1 - ${#t}) / c2 )) $2" else echo "0 $2" fi } count_matches abcba b Both produces output: 2 b Update: If you want to see the matches you can use a function like this. You can also try other regular expressions not just literals. function find_matches { MATCHES=() local STR=$1 RE="($2)(.*)" while [[ -n $STR && $STR =~ $RE ]]; do MATCHES+=("${B

Categories : Regex

Regex Match complex expression
Something like this should work: ^A ([<>!]=?|=) -?d+( (and|or) A ([<>!]=?|=) -?d+)*$ It allows for expressions where A is compared to some positive or negative integer using one of the comparitors <, >, !, <=, >=, !=, followed by bay any number of other similar expressions, separated by and or or—you listed ! and != as separate symbols, so I've allowed both as comparators, i.e. my solution actually allows expressions like A ! 2. If this is not desirable, replace ([<>!]=?|=) with ([<>]=?|!?=) in the above pattern. You can test it out here. Here's a slightly simplified version you could try out as well: ^(A ([<>!]=?|=) -?d+( (and|or) |$))+$

Categories : Regex

What regex expression will match all characters except ", except when it is "?
You could use this: "((?:[^"]|\")*)" It will match zero or more of any character other than a double-quote or a slash-double-quote pair, all surrounded by double-quotes.

Categories : Regex

What's the meaning of this perl regex expression?
You can use different delimiters instead of /. For instance you could use: m#/([^=]+)="(.+)"#o Or m~/([^=]+)="(.+)"~o The advantage here of using something different than / is that you don't have to escape slashes, because otherwise, you'd have to use: m//([^=]+)="(.+)"/o ^ [Or [/]] ([^=]+) is a capture group, and inside, you have [^=]+. [^=] is a negated class and will match any character which is not a =. ^ behaves differently at the beginning of a character class and is not the same as ^ outside a character class which means 'beginning of line'. As for the last part o, this is a flag which I haven't met so far so a little search brought me to this post, I quote: The /o modifier is in the perlop documentation instead of the perlre documentation since it is a quote-like

Categories : Regex

Match Timestamp with regex expression
Try grep -E '[[0-9]{2}/[A-Z][a-z]{2}/[0-9]{4}:[0-9]{2}:[0-9]{2}:[0-9]{2}.*]' <<<"[12/Jun/2013:06:31:31 -0700]" But this will only match the string in the described format. You will probably need to check if that date is correct. Because the string "[94/Non/2084:54:71:99 +9999]" will be matched with this regexp as well. Of course you can make a regexp with date validation, but the regexp will be like 3 times longer. Consider using python date and time libs for checking the valid format. You can also use unix date program date -d "now" "+[%d/%b/%Y:%H:%M:%S %z]" will print the format you want of the date now. Obviously date -d needs the correct specific input, so you need to adjust that input and then call date proper=`date -d "12/01/2013 06:31:31" "+[%d/%b/%Y:%H:%M:%S

Categories : Regex

Using regex replace to transform an expression
After Qtax's comment, I just wrote a solution: var st = "{op1 == op2, #} && {op3 > op4, 1, 2} && op5 == op6"; var regex = "{.*?}"; for (var match = Regex.Match(st, regex); match.Success; match = Regex.Match(st, regex)) { var oldString = match.Value; // {op1 == op2, #} var op = oldString.Split(' ').ToList()[1].Trim(); // == var csv = oldString.Split(',').Select(x => x.Trim()).ToList(); // [0] = "{op1 == op2" [1] = "#}" var expression = csv[0].Remove(0,1); // op1 == op2 csv.RemoveAt(0); var extension = "_" + String.Join("_", csv); extension = extension.Remove(extension.Length-1); // _# var newString = expression.Replace(op, op + extension); st = st.Replace(oldString, newString); }

Categories : C#

Match pattern in regex expression
Try using this pattern: ^(?< pol>w+)_(?< fac>[^_]+)_(?< end>w+)_(?< op>w+) The [^_] bit a character class which means 'match anything except an underscore'. If the delimiter is |, you'll have to use | in your pattern, because | has special meaning in regular expressions (although you won't need to escape it inside a character class). Like this: ^(?< pol>w+)|(?< fac>[^|]+)|(?< end>w+)|(?< op>w+) On a side note, I find it's much easier to use verbatim strings when specifying a regular expression pattern because you won't have to type in so many escape sequences: new Regex(@"^(?< pol>w+)|(?< fac>[^|]+)|(?< end>w+)|(?< op>w+)"); However, in this case, you might be better off just using Split: var result = input

Categories : C#

Replace expression with subsection using regex?
Basic regex -- nothing fancy or complex at all Search for: (clip.data('[a-zA-Z0-9]+')s*, ($[a-zA-Z0-9]+.val()());) Replace with: $2$1$3 The only PhpStorm-related thing here is replacement string format -- you have to "escape" $ to have it work (i.e. it has to be $2 to use 2nd back-trace instead of just $2 or 2 (as used in other engines)). This will transform this: clip.data('gameId' , $clipDetailsGame.val()); clip.data('title' , $clipDetailsTitle.val()); clip.data('byline' , $clipDetailsByline.val()); clip.data('team1' , $clipDetailsTeamOne.val()); clip.data('team2' , $clipDetailsTeamTwo.val()); clip.data('refereeId' , $clipDetailsReferee.val()); clip.data('description' , $clipDetailsDescription.val()); clip.data('competitionId', $clipDetailsCompeti

Categories : Regex

Simple regex expression advice
If the text : "in stock" is fixed you can simply get the 14 with : (d+) in stock In the first capturing group you will find the number 14 If you want to match only yhe number 14, you can use a look ahead expression : (d+)(?= in stock)

Categories : Regex

how do i get the last last group in a regex expression in clojure
(.* [.&;^])(?:[^*])([^]]+)$ Use a $ to denote the end of the string your matching your regex on. edit Since you don't supply a full example of the string your matching on, there's the possibility that the end of the string doesn't occur right after your last matching group, in which case you'd need to use a negative look ahead before the $ make sure there's no more capturable data.

Categories : Regex

Detect terms in an expression using regex
Try this regex: /[+-]?[^+-]+/g Here's a quick explanation: [+-]? // Optionally find either a + or a - [^+-]+ // Find as many non-plus-or-minus characters as possible See it here in action: http://regex101.com/r/qA6nS0

Categories : C++

RegEx expression not alerting properly in JS
input elements do not have .innerHTML. Use .value instead: var name = document.getElementById("name"), full_name = name.value, full_name_split = full_name.split(" ")[0];

Categories : Javascript

Regex expression for timestamp with or without leading zero?
Your pattern has a number of other problems. [1-60] is a character class. It will match a single 1, 2, 3, 4, 5, 6, or 0 character. Secondly, the . in your pattern matches any character not just a literal .. I think what you're looking for is something like this instead: d{1,2}:d{1,2}:d{1,2}.d{1,2} This will match any one or two digits, followed by a literal :, followed by any one or two digits, followed by a literal :, followed by any one or two digits, followed by a literal ., followd by any one or two digits. Or to check match only particular ranges of each time component, you can use a pattern like what chrylis suggests, although I'd generally recommend actually parsing the time value if you really need to do this.

Categories : Java

How can I write a REGEX expression for this crazy thing?
Assuming you're trying to extract the number located in the first td cell, searching for the tag start and end and using substring to extract the contents is a much easier approach than a regular expression. // text contains the HTML from your question int tdIndex = text.indexOf("<td"); int endTdIndex = text.indexOf(">", tdIndex + 1); int endTdTagIndex = text.indexOf("</td>", endTdIndex + 1); String numString = text.substring(endTdIndex + 1, endTdIndex - 1); // numString now contains 69144 If you need the contents of a td cell from deeper into the HTML, then you can search for later td tags by using the following in a loop: tdIndex = text.indexOf("<td",tdIndex+1); You'll have to know which td tag you're after (e.g., "the third td") and know that there will always be

Categories : Java

Regex expression to match " delineated string
Off the top of my head, if "[^"]*" mostly works for you, try "[^"]*("|$). This in theory should match something with quotes on either end, or something started by a quote and ended by the end of the line.

Categories : C#

Regex for 8-digit expression without hyphen or letters
I think you need a very simple pattern. ^d{8}$ Short description Assert position at the beginning of the string ^ Match a single digit 0..9 d Exactly 8 times {8} Assert position at the end of the string (or before the line break at the end of the string, if any) $

Categories : Regex

Haskell regex-pcre negate expression
What you are looking for is a split: split your string with your original pattern and you will obtain what you want. OR you can try to match with: (?>\s\s+\K|^)(?>\S|\s(?!\s+))++ and (?>/\*[^*]*\*/\K|^)(?>[^/]++|/(?!\*[^*]*\*/))++ where K is a pcre feature that resets the begining of the match.

Categories : Regex

RegEx that matching an expression NOT at the beginning of a line
If you are trying to match vol/vol./volume that is not at the beginning of a line, the following should work: ^.+(vol.?|volume) ^.+ means match 1 or more characters from the beginning of the line (vol.?|volume) means match vol followed by an optional . or match volume

Categories : Java

Regex expression for at least one upper, lower and digit
Yes you are on the right track.. Just remove .+ from your regex,it is redundant and doesn't really add anything to the regex If you want to match more than 6 characters you should use .{7,}

Categories : Regex

Regex expression to extract everything inside brackets
Use lookaheads: "(?<=\()[^)]*?(?=\))". Watch out, as this won't work for nested parentheses. You can also use backreferences.

Categories : C++

Regex substitution: what is the difference between $& and Value (in lambda expression)?
Lambdas are anonymous methods which work just the same as regular ones. The one declared in your example is equivalent to: string Convert(RegexMatch match) { return "test" + match.Value; }. Using this syntax can give you access to a much richer range of possibilities then using the Regex expression used in your first example.

Categories : C#

Regex expression assistance email content
My solution would be along the following lines, given the content of the email saved as lines in an array named $myarray and storing into $outarray: $doquote = FALSE; foreach ($myarray as $val) { if (strpos($val, 'Quoting') !== FALSE) $doquote = TRUE; if ($doquote) { if (preg_match('[|>]', $val, $matches) == 1) { array_push($outarray, $matches[1]); } } }

Categories : PHP

Regex for parsing string with same type of expression
You can use lookarounds which perform only a check but don't match: lookahead (?=...) lookbehind(?<=...) example: (?<=\"6\":\")[^"]++(?=") An another way is to use a capturing group (...): \"6\":\"([^"]++)" Then you can extract only the content of the group. Example: Pattern p = Pattern.compile("\"6\":\"([^"]++)""); Matcher m = p.matcher(yourString); if (m.matches()) { System.out.println(m.group(1)); }

Categories : Java

How to just more a string of more than 1 character in a regex replace expression vb.net
This is not how negated character classes work. The class disallows any single of the characters /, r, e, f, >. Also, you don't even want to rule out /ref> at all, because you want to remove all the intermediate refs as well. You can simply use .*. Also, you don't want lookarounds, because these exclude the things matched inside them from the match. But you do want to remove those tags as well. Hence, in your case, it should be as simple as: "<ref.*/ref>" Since * is greedy, this match will simply go from the first <ref to the last /ref> - usually a big problem of greediness, but in your particular case exactly what's desired. You might want to use RegexOptions.Singleline so that . matches line breaks, if there are any.

Categories : Xml

Regex expression - one or multiple strings seperated by comma
^(foo|bar)(,(foo|bar))*$ does that. The capturing groups are not necessary, you could also write this (slightly more efficient) with non-capturing groups as ^(?:foo|bar)(?:,(?:foo|bar))*$ To avoid repeats, you can use a negative lookahead assertion: ^(foo|bar)(?:,(?!1)(?:foo|bar))?$ (Notice the ? instead of * - if only a single repetition is possible, this makes more sense.) This approach quickly becomes complicated when a higher number of strings is to be checked. While it's theoretically possible to do that with a regex as well, it's probably not a good idea.

Categories : Regex

Regular expression conundrum - PowerShell (.NET regex engine)
As for the nested patterns - generally regexes are not the tool for that because they origin from grammar that can not handle "counting". But in .NET (and therefore also in PowerShell) it might be possible. Have a look at http://blogs.msdn.com/b/bclteam/archive/2005/03/15/396452.aspx . There are probably also other sources, but this one is the first I ran over.

Categories : Dotnet

Regular Expression (Regex) for pulling name between quotations - Powershell
if ($subject -cmatch '(?<=")[^"]*(?=")') { $result = $matches[0] } This looks for any number of characters except quotes ([^"]*), but only if they are preceded by a quote ((?<=")) and followed by a quote ((?=")). It does not even try to handle escaped quotes.

Categories : Regex

Regex expression to search upto nested level
You could get this result using (?<={)[^{}]*(?=}), assuming a language other than JavaScript. In C#, for example, that's result = Regex.Match(str, @"(?<={)[^{}]*(?=})").Value; If you're using JavaScript, use {([^{}]*)} and access $1 for the match result: var myregexp = /{([^{}]*)}/; var match = myregexp.exec(subject); if (match != null) { result = match[1]; }

Categories : C#

Matching an expression including arbitrary lines with regex in Vim
If you want to use the more common (...) for grouping, you need to include the v atom to switch Vim's regular expression syntax to "very magic"; else, it's (...). But for your case, Vim has a special atom that matches arbitrary characters including newlines: \_., like this: /DRIVER_ACTIVITY\_.*DriverGroup There's no way around learning Vim's different regular expression dialect; see :help pattern.

Categories : Regex

Textbox check with Regex expression not allowing decimal
I think the problem is that you are trying to validate the number character-by-character as the user types, but it is not possible to type a valid decimal number without the value being an invalid value temporarily. Consider what happens as the user types the value 1.2: The user types the character 1. Validation fires because the value of the textbox changed. 1 is a valid decimal, so validation passes. The user continues typing, adding the decimal point character . Validation fires again because the value of the textbox changed. 1. is not a valid decimal according to the regular expression, so the last character is erased. The value of the text box is now back to 1. The user gets frustrated. Goto step 4. As you can see, it's not possible to enter the decimal point. But, if you try

Categories : C#

How to give regular expression for Regex.ismatch function?
Here's the Regex.IsMatch that does what you want: Regex.IsMatch("12345678901234.12", @"^d{1,14}(?:.d{1,2}){0,1}$") That particular regex is for a number up to 14 digits before the decimal point and 1 or 2 digits after the decimal point (with the whole decimal part being optional) A good place to test it is here: http://regexhero.net/tester/ Because you've mentioned ^ and $, I've included them in the regex, which will only parse lines with just the number (so, for example " 1234.12 " won't return true in the IsMatch, just remove the "^" and "$" if that is not important). Another good resource for regex is this: http://www.mikesdotnetting.com/Article/46/CSharp-Regular-Expressions-Cheat-Sheet UPDATE: Since the goal is that the user cannot write anything other than something that satis

Categories : C#



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