w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Meta Regex: test if regex is only a string (no regex "wildcards")
Well, there's a quick two-step way to test for this. Instead of testing for escaped characters and wildcards in one regex, the first line of your function could remove escaped characters, then the second line would test the remaining string for wildcard-type expressions. .*(([.+?])|({[0-9]*,[0-9]*})|(*)|(+)).* will match a string that contains any *, +, {#,#}, or [] expression. In your function, return whether or not the passed string matches this expression.

Categories : C++

java.util.regex.PatternSyntaxException: Syntax error in regex pattern near index
+ should be escaped, cause + is used to represent one of the quantifiers it should be s.split("\+");

Categories : Java

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++

Ignore REGEX in MVC model or Select another REGEX depending upon User input
There are a few different options for you: Create a 100% custom validation attribute that combines the Required and RegularExpression attributes to your needs. So inside that custom attribute you would do all the validation that you need and compare the value to the Country property to selectively apply the RegEx as needed. Create a different postcode attribute per country that you care about and use something like the `RequiredIfAttribute (see RequiredIf Conditional Validation Attribute) to determine which one is actually required. You can then use Javascript to show/hide the appropriate input fields.

Categories : C#

java regex what the heck? am I misreading the regex docs completey?
String#matches() tests this string against the entire pattern. Let's take a trip down JavaDoc lane: String#matches(String) Tells whether or not this string matches the given regular expression. An invocation of this method of the form str.matches(regex) yields exactly the same result as the expression Pattern.matches(regex, str) so let's trace it through: Pattern#matches(String regex, CharSequence input) Compiles the given regular expression and attempts to match the given input against it. An invocation of this convenience method of the form Pattern.matches(regex, input); behaves in exactly the same way as the expression Pattern.compile(regex).matcher(input).matches() One last step: Matcher#matches() Attempts to match the entire regio

Categories : Java

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

Pass regex special characters through web form to PHP regex
I don't know better ways (don't think there are any…), but one way would be to just remove the backslash before asterisks after the preg_quote function call: $find = str_replace("\*", "*", $find);

Categories : PHP

Regex performance issue - can anyone explain way this regex is slow
A and  means beginning and the end of the string. Therefore the regex is more limited and has less searching to do. For example if your text has newlines in it, the 2nd regex is way faster since it only searches the first new line where the 1st regex keeps searching

Categories : C#

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

rewrite VBScript.Regex to C# Regex code
Try this: Regex re = new Regex(@"({ ?)|(""(""""|[^""]*)*"")|([^},{]+)|(, ?)|(} ?)", RegexOptions.IgnoreCase | RegexOptions.Multiline); MatchCollection matches = re.Matches(textBox1.Text); var Tree = new SimpleTree<string>(); foreach (Match m in matches) { if( m.Groups(4).Value != null ) { // do your stuff here } }

Categories : C#

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

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

translate Ruby regex to php/perl regex
You have a strange error in your Regexp. I think it's partially luck it's working on Rubular: (1?[[(s.-]]d{3})?[s.-]d{3}[s.-]d{4}(z[^d])?) ^ ^ Why are those brackets there two times? See here for a working version where I just removed those. Works fine with PHP now: http://www.regex101.com/r/gR6kS3 (1?[(s.-]d{3})?[s.-]d{3}[s.-]d{4}(z[^d])?)

Categories : PHP

Replace multiple regex into one regex in perl
You can do it like this: message =~ s# &lt; (?<tag>span|em|ul|ol) &gt; (.*?) &lt; / k<tag> &gt; # <$+{tag}> $2 </$+{tag}> #xg;

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

(Bash) Regex variable inside another regex
The immediate problem is not a regex issue. You have your $tldlist variable inside single quotes, and single quotes prevent variable expansion. Change your second line to, e.g.: curl="$(curl -vfIk https://$hostname 2>&1 | sed 's/^* //g' | tr '[A-Z]' '[a-z]' | grep -i --color=never -E "CN=(.*).$tldlist")" so as to allow $tldlist to expand.

Categories : Regex

Multiple matches of regex within other regex
You can use look-around. (?<=one)(bla)*(?=one) Positive look-behind ((?<=...)) checks that the previous characters match some pattern. Positive look-ahead ((?=...)) checks that the next characters match some pattern. Look-around is not included in the matched string. Test. Or you can simply put the part you want to extract in brackets and extract group 1. (the ?: is to make (bla) a non-capturing group, it doesn't change the match, just what gets captured). one((?:bla)*)one Test.

Categories : Regex

regex multiple replaces in one go using c++ regex
Description Regex: ^(.*?)TableOne[.]@ColumnTwo,s+(.*?)[@](.*?)$ Replace with: 123 Example This is C# example is added to show how the regex works. using System; using System.Text.RegularExpressions; namespace myapp { class Class1 { static void Main(string[] args) { String sourcestring = "SELECT TableOne.ColumnOne, TableOne.@ColumnTwo, TableOne.ColumnThree FROM TableOne WHERE TableOne.@ColumnTwo ='abc'"; String matchpattern = @"^(.*?)TableOne[.]@ColumnTwo,s+(.*?)[@](.*?)$"; String replacementpattern = @"123"; Console.WriteLine(Regex.Replace(sourcestring,matchpattern,replacementpattern,RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline)); } } } $sourcestring after replacement: SELECT Table

Categories : C++

How to convert this PHP Regex to Javascript Regex?
In JS, you can do it simple do a .test() with Regex(no need to change the expression). var yourRegEx=/^(([^,]+,){4}[^,]+ ){3}$/; if(yourRegEx.test($all_questions) { // replace $all_questions with your // js variable }

Categories : Javascript

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 use two types of regex in single regex?
Yes..you can use |(OR) between those two regex.. [\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}|\d+ ^

Categories : Java

Regex for Regex validation decimal[19,3]
Simplification: The d doesn't have to be in []. Use [] only when you want to check whether a character is one of multiple characters or character classes. . doesn't need to be escaped inside [] - [.] appears to just allow ., but allowing to appear in the string in the place of the . may be a language dependent possibility (?). Or you can just take it out of the [] and keep it escaped. So we get to: d{1,16}|d{1,16}.d{1,3} (which can be shortened using the optional / "once or not at all" quantifier (?)      to d{1,16}(.d{1,3})?) Corrections: You probably want to make the second d{1,16} optional, or equivalently simply make it d{0,16}, so something like .1 is allowed: d{1,16}|d{0,16}.d{1,3} If something like 1. should also be allowed, you'll need to add an

Categories : Regex

Check the end of a string for valid regex and return the string trimmed of the regex-
You should simply replace: str = 'testfoostringfoo'; var regex = /foo$/; str = str.replace(regex, ''); return str; I removed the if, replace does not affect the string when regex is not found. Keep in mind that match returns an array of matches (['foo']), so the comparison to true fails either way: the condition in if(str.match(regex) == true) is always false. You're looking for if(str.match(regex)) or if(regex.test(str)). Note that trim is somewhat new in JavaScript, and it doesn't take parameters, it just removes whitespaces.

Categories : Javascript

Java UIMA: Regex Variable inside Regex Variable?
According to the docs, The regex variable name can contain any of the following characters [a-zA-Z_0-9]. Other characters are not allowed. If that's the only restriction, 123 would be a valid name, which you would refer to as value="v{123}". How is the parser supposed to know you mean the rule named "123" and not one hundred and twenty-three vertical tab characters? In most languages (including XML), names can't start with digits. If that were the case here, it would be possible to embed variable names in variable definitions, because v{month} or v{_123} is guaranteed to be invalid in a Java regex. (Other regex flavors are more liberal; they would interpret the braces as literal brace characters because {month} and {_123} can't be interpreted as range expressions.) The only wa

Categories : Regex

Convert JS Regex to PHP Regex
You can do it like this: $messagetext = preg_replace('~^h*+#Kw++~m', '<a class="myHashtag" ' .'href="http://search.twitter.com/search?q=%23$0" target="_blank">#$0</a>', $messagetext); pattern detail: ^ # line's begining h*+ # horizontal space (ie space or tab), zero or more times (possessive) # # literal # K # forgets all the begining! w++ # [a-zA-Z0-9_] one or more times (possessive) Delimiters are ~ but you can choose other characters. I use the multiline mode (m modifier), thus ^ stands for line's begining. (possessive) indicates to the regex engine that it don't need to backtrack by adding a + after a quantifier. The subpattern becomes then more efficient.

Categories : PHP

Convert JavaScript Regex String to PHP Regex String
Regular expressions are not language specific. They are applicable in most coding languages and used the same way -- the only difference is how they are applied. For PHP, use methods such as preg_match or preg_replace. For more information on Regular Expressions, go here. If you go to Languages and Libraries, you can see all the coding languages that support Regular Expressions. Some may require libraries or packages, but in general the way you write regular expressions is fairly universal. EDIT: I stand corrected as there are some very slight variations between different coding languages for how they handle Regex. You can find out how to make Regular Expressions for PHP here: http://www.php.net/manual/en/regexp.introduction.php You can also get more information on some of the subtle d

Categories : PHP

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

How to do 'NOT' in regex?
try this: str.split("(?<!\\);"); EDIT if you do want to have the spliter (the ;) in result array: str.split("(?<=[^\\];)"); Note that single look-behind is sufficient for this problem. and this time, I did a test: final String str = "sometexthere\;shhshshshhs;shhshshshshs\;dddddd;"; System.out.println(Arrays.toString(str.split("(?<=[^\\];)"))); it outputs: [sometexthere;shhshshshhs;, shhshshshshs;dddddd;]

Categories : Java

Regex: Getting a certain value from a URL
Not knowing how you are going to go about using regex to pull the number out, or what code is surrounding it, d+ will match to one or more numbers. See here for a reference page on basic regex syntax. Edit: Because you have other numbers in there, I'd use either A) a look behind (as long as you aren't doing the regex in JavaScript, as it doesn't support look behinds) or B) by defining the minimum number of characters you want to make. A) d+(?<=/d+) - match one or more numbers, look behind to check that there is a / preceding the numbers B) d{5,} - match any numbers, at least 5 of them, with no upper limit on how many it can match

Categories : Regex

Look Behind Regex
You do need lookaround but I'd use a positive lookahead assertion for that: (?=(([ABC])2)) Your match results will be in match.Groups(1) of each match object. Explanation: (?= # Look ahead to check that the following matches: ( # Match and capture in group number 1: ( # Match and capture in group number 2: [ABC] # Any letter A, B or C ) # End of capturing group 2 2 # Now match that same letter again. ) # End of group 1. It now contains AA, BB or CC ) # End of lookahead assertion A simpler solution: (?=(AA|BB|CC))

Categories : C#

Can it be done with regex?
The dot in regex has a special meaning: "any character here". If you mean a literal dot, you should escape it to tell the regex parser so. Escape dot in a regex range

Categories : Javascript

GS1-128 and RegEx
Try this: ^(?<gtin>(01))(?<comp_code>12345678)(?<part_code>d{5})0?(?<pd_ed>((?:11|17)))(?<date>d{6})(?<bat_no>((?:21|10)))(?<data_req>d{1,20}?)(?<count>(?:(30))?)(?<data_opt>(?:d{1,8})?)$ The above expression should match all the following items: (01)12345678654320(11)120500(21)1234567890 (01)12345678124570(17)130700(10)30567(30)50 (01)12345678888880(11)140200(21)66503042(30)100 Explanation: <!-- ^(?<gtin>(01))(?<comp_code>12345678)(?<part_code>d{5})0?(?<pd_ed>((?:11|17)))(?<date>d{6})(?<bat_no>((?:21|10)))(?<data_req>d{1,20}?)(?<count>(?:(30))?)(?<data_opt>(?:d{1,8})?)$ Assert position at the beginning of the string «^» Match the regular expression below and capture i

Categories : C#

What does the "(?i)" mean in Regex?
It's a way of specifying that the matching should be case insensitive. Here's the MSDN page on Regex options: By applying inline options in a regular expression pattern with the syntax (?imnsx-imnsx). The option applies to the pattern from the point that the option is defined to either the end of the pattern or to the point at which the option is undefined by another inline option. But really, it looks like you're processing XML, in which case, you should really be using an XML parser, not regular expressions. There are classes built into the framework for working with XML which properly respect all of the rules of XML. Treating XML as "just a string" tends to lead to brittle solutions.

Categories : Asp Net

where do I put my regex
Here's one way to use your regex to only get the two matching lines: $('#test h4 a').each(function () { var $link = $(this), text = $link.text(); if (/^.*(Gold|Silver).*$/.test(text)) $link.after(text); $link.remove(); }); That is, in your .each() loop you can remove the link every time, but before that only add the text in if the item matches. Demo: http://jsfiddle.net/nFnEF/1/ To remove the "Metal Price..." part, you can do a .replace() with a different regex that captures the two parts you want to keep: var re = /^(Gold|Silver)[^-]+-s?([d.]+)$/; $('#test h4 a').each(function () { var $link = $(this), text = $link.text(); if (re.test(text))

Categories : Jquery

What does the "[^][]" regex mean?
[^][] is a character class that means all characters except [ and ]. You can avoid escaping [ and ] special characters since it is not ambiguous for the PCRE, the regex engine used in preg_ functions. Since [^] is incorrect in PCRE, the only way for the regex to parse is that ] is inside the character class which will be closed later. The same with the [ that follows. It can not reopen a character class (except a POSIX character class [:alnum:]) inside a character class. Then the last ] is clear; it is the end of the character class. However, a [ outside a character class must be escaped since it is parsed as the beginning of a character class. In the same way, you can write []] or [[] or [^[] without escaping the [ or ] in the character class. You can use this syntax with several rege

Categories : PHP

What does regex [*f]+ mean?
The default value matches asterisks and page breaks: "[*f]+" http://www.emacswiki.org/emacs/OutlineMode#toc2

Categories : Regex

Regex X and/or Y
[XY]+ to get any number of Xs and Ys (so includes XYYXYX, etc). Or... [XY]{1,2} to select 1-2 Xs and Ys (which only includes your 4 examples).

Categories : Java

Regex in std c++
There is nothing wrong with the regular expression, but you need to search for it repeatedly. And than you don't really need the parenthesis anyway. The std::regex_search finds one occurence of the pattern. That's the {aaa}. The std::wsmatch is just that. It has 3 submatches. The whole string, the content of the outer parenthesis (which is the whole string again) and the content of the inner parenthesis. That's what you are seeing. You have to call regex_search again on the rest of the string to get the next match: std::wstring::const_iterator begin = chatMessage.begin(), end = chatMessage.end(); while (std::regex_search(begin, end, m, e)) { // ... begin = m.end(); }

Categories : C++

Regex - more than one "does not contain"/"contains"
For your example, I'd use lookahead assertions like this: ^WORD_A(?=.*WORD_B)(?!.*WORD_C).*WORD_D$ You can always add more conditions if you want (just add another lookahead). For example, if you want to match any string that contains WORD_A and WORD_B and does not contain WORD_C nor WORD_D: ^(?=.*WORD_A)(?=.*WORD_B)(?!.*WORD_C)(?!.*WORD_D)

Categories : Regex



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