w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Regular Expression To Fail On Character In One Place But Match If Character Used Later On
Use lookahead, maybe something like /[-+]?[0-9,.]+s*(?![+-*/^s0-9,.])/. Note that what you want to match is also in that lookahead, because otherwise it'd just break off in the middle of the string, for example "23+" would match the "2" because "3" not one of those disallowed characters.

Categories : Javascript

Regular Expression library that maintains state, takes input character by character and returns true whenever match is found
For C++ I recommend boost Xpressive: http://www.boost.org/doc/libs/1_53_0/doc/html/xpressive.html For C pcre might be in order: http://www.pcre.org/ About your constraint, you might try to wrap that logic into an input iterator for Xpressive.

Categories : C++

Regex to match text after a given character excluding the character itself
Look-around could be an option: (?<=")[^"]*(?=") (?<=") checks that the previous character is a ". (?=") checks that the next character is a ". Test. An alternative is just to use grouping: "([^"]*)" How to extract the group is dependent on the language used. Test. (note the "Matching groups" area) I didn't simply use "(.*)" because the string abc "def" "ghi" will match "def" "ghi", though you may have wanted to match "def" and "ghi" separately. An alternative to [^"] is non-greedy matching - "(.*?)", which will match as little of the string as possible.

Categories : Regex

Regex match up to character unless character in between
How about this: (.*?)([^s(]*(?=s|$))? It matches something in brackets, then optionally matches any number of non-space non-) characters followed by look-ahead to match a space (or end-of-string, in case it may appear at the end of the string). Note that there shouldn't be a | in [] (unless you want to match the | character). Live demo (surrounded by brackets and added non-capturing group (?:)).

Categories : Regex

Python script to glean data from 2 spreadsheets, compare them to find a match, and generate a new spreadsheet
It's a little hard to tell what you mean without sample input data. You've also got some confusing unnecessary code and removing that is the first step. while 1: for foo: goLine=goow [etcetera] break does the same thing as for foo: goLine=goRow [etcetera] so you can get rid of your "while" and "break" lines. Also, I'm not sure why you're catching StopIteration. Delete your try / catch lines.

Categories : Python

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

match first character in a regex?
http://([^/:]*):?([0-9]*)(/.*) The first group is matching everything but : and now I added /, that's because the [^] operator means match everything but what's inside the group, everything else is just the same. Hope it helped!

Categories : Regex

How to match a character only when a condition is met?
You would need to add a space to it like: [([a-zA-Z0-9_]+)(?:s+)([a-zA-Z0-9_]+:[a-zA-Z0-9_]+(?:s+))*] I added a capture group for the AttributeName and a non capturing group for the spaces.

Categories : Regex

Regex match any character NOT followed by "? something"
Use parse_url: print_r(parse_url('/something/contentimg/coast03.jpg?itok=ABC')) ( [path] => /something/contentimg/coast03.jpg [query] => itok=ABC )

Categories : Regex

How to match 1 character in a string
You can use a negative lookahead assertion as follows: <snip> PASSWORD_PATTERN_LOWER_8 = "(?i)^(?!.*(.).*\1)"; Explanation: (?i) # Case-insensitive mode ^ # Match start of string (might be redundant, but won't hurt either) (?! # Assert that it's impossible to match... .* # any string (.) # that's followed by one character (captured into group 1) .* # followed by any string \1 # and a repetition of the character we captured before. ) # End of lookahead Performance will not be that great, especially with longer strings, because in the worst case, every character will have to be compared with every other character. For example, the password .qwertzuiopasdfghjklöäyxcvbnm,. will only be detected as invalid after over 1000 steps of the regex engine, whereas q

Categories : Java

Match only a newline character
The simplest way count the number of lines in the file: private static int LineCounter(string filePath) { string[] lines = File.ReadAllLines(filePath); return lines.Length; }

Categories : C#

How to find exact match using PSLIST and FIND in Batch/CMD
How about using the -e parameter of pslist? pslist -e notepad It will set errorlevel to 0 when found, and 1 when not found. Also it is an exact match meaning it will not identify notepad++. PSList Help pslist v1.3 - Sysinternals PsList Copyright (C) 2000-2012 Mark Russinovich Sysinternals - www.sysinternals.com Usage: pslist [-d][-m][-x][-t][-s [n] [-r n] [\computer [-u username][-p password][name|pid] -d Show thread detail. -m Show memory detail. -x Show processes, memory information and threads. -t Show process tree. -s [n] Run in task-manager mode, for optional seconds specified. Press Escape to abort. -r n Task-manager mode refresh rate in seconds (default is 1). \computer Specifies remote compu

Categories : Batch File

Match characters within a special character
This regex will match them: (?<=%).*?(?=%) Use your application language (unspecified) to extract them. If your application language doesn't support look arounds, use group 1 from this regex: %(.*?)%

Categories : C#

Match and replace first and last character in string
There's no need for a regular expression. Just use this: string result = input.Trim('%'); But if you really need a regular expression, you'd need to use start (^) and end ($) anchors, like this: string result = Regex.Replace(input, "^%|%$", "");

Categories : C#

Perl - substitute first character before match
This is a way to insert a semi-colon after the first semi-colon and whitespace, but before the first non-whitespace. s/;s*K(?=S)/;/ If you feel the need, you can use w instead of S, but I felt with this input it was an unnecessary specification. The K (keep) escape is similar to a lookbehind assertion in that it does not remove what it matches. The same goes for the lookahead assertion, so all this substitution does is insert a semi-colon in the designated spot.

Categories : Regex

Match character from a group of characters in php
You need array for chars collection and in_array() function that checks if a particular element is in the array: $chars = array('a', 'f', 'h', 'k'); if (in_array('f', $chars)) { echo 'hello'; }

Categories : PHP

Match string with php dom xpath by first and last character
This isn't XPath's strong point - what you're describing would be best handled by a REGEXP engine (which, in PHP, would presumably mean iterating over the nodes and running each one through preg_match). Nonetheless, here's a (very) hacky XPath approach which I think does what you want. You can see a working demo at this XMLPlayground. root/node[ substring(., 1, 1) = '%' and substring(., string-length(.)) = '%' and not(string-length(translate(substring(., 2, string-length(.)-2), 'abcdefghijklmnopqrstuvwxyz0123456789-:', ''))) and ( ( contains(., '::') and substring(., 2, 1) != ':' and substring(., string-length(.)-2, 1) != ':' ) or not(contains(., '::')) ) ]

Categories : PHP

php character match and allow special characters
When you create a new mysql table, you can choose between different character sets. Many have "_ci" in their name, which means "case insensitive". Looks like you need to choose a case sensitive one.

Categories : PHP

How do I match 2 columns data and when a match is found copy a 3rd column of data to a 4th blank column
This can be done with a lookup using Index/Match. Assuming row 1 has labels, start in C2 with =index(A:A,match(D2,B:B,0)) If you swap columns A and B, you can use a Vlookup(): =vlookup(D2,$A$1:$B$1000,2,false) Copy down.

Categories : Excel

RegEx: match any non-word and non-digit character except
First of all, you must know that W is equivalent to [^a-zA-Z0-9_]. So, you can change your current regex to: [\W] This will automatically take care of D. Now, if you want to ignore some other character, say & (underscore is already exluded in W), you can use negated character class: [^\w&]

Categories : Java

Match a special utf8 character regex
is unnecessary except for - (dash). >> 'Testshop – Best fan ware | Example shop'[/[^|-;–]*/] => "Testshop " If you want only alpha-numeric chracter, use w+ (also match _): >> 'Testshop – Best fan ware | Example shop'[/w+/] => "Testshop"

Categories : Ruby

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

Regex to match only one character sequence within string
What you want is called a non-capturing group. There are already some fairly high-quality examples of doing this in Java on SO - for example, this question: Non capturing group?

Categories : Java

How to match regex with same format but different in terms of character set?
do you mean (&|?)([^&=]+)=(&|$) (you can use non capturing groups if you need) but I would just build a hash of all query string parameters and pick the keys without values. it is cheaper.

Categories : Regex

Perl: How to match specific character in a string?
open my $File1, "<", "File1" or die $!; open my $File2, "<", "File2" or die $!; my @arr1 = map { s|s+$||g; s|*|.|g ? qr/($_)/ : qr/(w*$_w*)/; } <$File1>; my $str = do { local $/; <$File2> }; print "$_ " for map $str =~ /$_/g, @arr1; output: b05ldt10ud0e0 b05dcc00ud0c0 b05mny00ud0b5 b05mny00ud0d3 b05mny00ud0m7 b05can03un0b5 b05mdd04un9c9

Categories : Regex

Python re.sub - replacing character when context does not match
Use a negative lookahead pattern: data = re.sub(r' (?!d{8})', '', data) For example, import re data = ''' 12345678 foo bar baz 12345678 foo ''' data = re.sub(r' (?!d{8})', '', data) print(data) yields 12345678 foobarbaz 12345678 foo

Categories : Python

Regex: How to match two character but exclude a certain combination
You can use a negative look-ahead. You can find more information on what that is here. Essentially, it "looks ahead" and ensures that the regex in the parentheses is not matched. DataFile_(?!en)w{2}.dat Note that you should be escaping that period, as it will match any character.

Categories : Python

Merge two data frame on one exact match and one partial URL match
You can put your data in the long format and then process by ID within a data.table . library(reshape2) dat <- do.call(rbind,lapply(list(pattern,dataset),function(x) melt(x,id.vars='SessionId'))) library(data.table) DT <- data.table(dat,key='SessionId') DT[,if(.N ==2) if(length(grep(value[1],value[2]))>0) as.list(value) ,by='SessionId'] SessionId V1 V2 1: 5b8cc8794a02ba868db21faef1 somewebsite.com/abc/detail/110302288511/ somewebsite.com/abc/detail/110302288511/110302288512/ 2: 5b8cc8794a02ba868db21faef3 somewebsite.com/abc/detail/110302288513/ somewebsite.com/abc/detail/110302288513/1103022815/ EDIT benchmarking the 2 solutio

Categories : R

preg_replace json string match same character beginning/end
Don't work on the json directly, decode it using json_decode(). Then cleanup your HTML using HTMLPurifier, which does a great job at cleaning HTML code. Then encode your data to json again using json_encode().

Categories : PHP

Regex to match any words with the following condition: after the character %, it's allowed only to have %s or %.[0-9]f
Use a double negative! (?!.*%(?!s|.[0-9]+f)).* So the nested negative lookahead will cause the outer negative lookahead to fail if the % is followed by s or a valid float expression (like %.3f). You may want to add a beginning of string anchor here to make sure you don't get partial matches. Example: http://rubular.com/r/VTzJEUAlpb

Categories : Java

Simple Perl string match with a special character i.e '
Your hash doesn't have a "Veteran's Affairs" key, it has a "Veteran's Affairs" value. If you defined your hash in the more common fashion: my %cot_descn = ( "Correctional" => "Veteran's Affairs", "State Pharmacy Assistance Program" => "VA Medical Center", "VA Mail Order Pharmacy" => "PHS 340B Entity" ); then the structure would be clearer. Since there is no "Veteran's Affairs" key, of course this test will send you into the else branch: if (exists $cot_descn{$var_cot_descn}) when $var_cot_descn is "Veteran's Affairs". Perhaps you have the first key/value in your %cot_descn backwards.

Categories : Perl

Python regex to match character a number of times
try with this kind of pattern (for 10 between 0 or 2 times): ^(([^1]+|1+(?=0))*10){0,2}([^1]+|1+(?=0))*$ You can easily adapt it for rabbit between 0 and 3 times: ^(([^r]+|r+(?=abbit))*rabbit){0,3}([^r]+|r+(?=abbit))*$

Categories : Python

RegEx to match any character except strings with surrounding prefixes
You syntax is a bit weird if you ask me... I would suggest: ^(?!{(?:[$@#]).*(?:[$@#])}).* Demo First 'group' is {(?:[$@#]) which looks for the opening prefix, then .* to match everything in the middle and (?:[$@#])} to match the closing suffix. Note that it will not allow things like: {$Hello Mars$} how are you? If you want it to accept this as well, add an end of line anchor: ^(?!{(?:[$@#]).*(?:[$@#])}$).* ^ Demo You can use the character class to have the different symbols [@$#] and is shorter than having multiple negative lookarounds or | operators in side :) EDIT: To prevent things like {#Free text which is fine$}' you could use: ^(?!{([$@#]).*1}).* Or ^(?!{([$@#]).*1}$).* For the second version. 1 is a backreference and refers to the fi

Categories : Regex

Python Regex Match for every single character in a "alphanumeric word"
You can use this regex that follows your description list: (?i)[dptu][a-z0-9]{3}[a-z][0-9]{5}[a-z]{4} (?i) is a modifier to make the pattern case insensitive

Categories : Regex

Java regular expression to match everything between same specific character sequences
Just change your second group into a lookahead foo(.*?)(?=foo|$) See it on Regexr The problem is you are matching the "foo" that you want to use as next start point. You can avoid this by using the lookahead assertion. This way the following "foo" is not matched and therefor used as start of the next match.

Categories : Java

Cygwin Regex Shorthand Character Classes Fail to Match
I'm pretty sure that cygwin uses the GNU grep regex, which doesn't support the d abbreviation, but does support [:digit:]. As an aside, I can't explain why you're matching the d in the case where you have multiple backslashes preceding the d outside of the character class brackets.

Categories : Regex

With jquery, match single character followed by colon and wrap in span tag
Try $('p').html(function(idx, html){ return html.replace(/([a-z]:)/ig, '<span>$1</span>') }) Demo: Fiddle

Categories : Javascript

Regex to match a-z spaces, character limit, only first letter capitalized
Let's try this: ^[A-Z]((?<= )[A-Z]|[a-z ]){2,29}$ [A-Z] -- a capital letter ( (?<= )[A-Z] -- either a capital letter preceded by a space | -- or [a-z ] -- a lowercase letter or a space ){2,29} -- 2 to 29 times (plus the initial capital) You will need to use the PCRE (not ereg_*) for the lookbehind to work. "My name Is bob" ↑ ↑ ↑ | | -- this is a "(?<= )[A-Z]" | --- this is a "[a-z]" ---- this is a "[ ]" "naMe" ↑ -- this is NOT a "(?<= )[A-Z]" (a character before the [A-Z] is not a space) EDIT: damn, you added the "Each word must be at least 2 letters". Use m.buettner's.

Categories : PHP

Regular expression match any character at the beginning end with specific string
Try this as a regex: /S+-line(?![-w])/ The word anchor is not suitable here since dashes are not considered part of a word, so /S+-line/ would mistakenly match text-with-line-not-to-be-replaced. Hence the lookahead construct. Of course, according to your use case, S may seem a little coarse. If your words really only consist of letters then dashes etc, then you can use the normal* (special normal*)* pattern: /[a-z]+(-[a-z]+)*-line(?![-w])/i (normal: [a-z], special: -) (edit: changed the lookahead construct, thanks to @thg435)

Categories : Javascript



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