regex-negation

Regex for Passport Number

China☆狼群 提交于 2020-01-21 12:30:08
问题 I am trying to implement regex validation for passport number. My requirement is Length should be minimum 3 characters to a maximum of 20 characters. Should not be only 0's I tried with the below regular expression ^(?!0{3,20})[a-zA-Z0-9]{3,20}$ This seems to work for most of the cases, but incase my text contains 3 or more leading zeros, it seems to fail. Such as '00000001'. Example Matches 101AE24 - Working as expected 00 - Not working as expected 01234 - Working as expected 00001 - Not

Add Trailing Slash to URLs

五迷三道 提交于 2020-01-19 03:48:07
问题 There are quite a few results for add trailing slash .htaccess on Google, but all examples I found require the use of your domain name, as in this example: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !example.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301] My problem is that a hard-coded domain name will not work on my local development machine. Is there a way to add trailing slashes without explicitly

Regex, Match uppercase characters not between brackets

时间秒杀一切 提交于 2020-01-16 18:48:12
问题 In RegEx, I search a pattern that selects multiple uppercase characters (more than 1), that are not enclosed by curly braces. It should match: ABC AB XYZABC but not: {ABC} {AB} {XYZABC} 回答1: The below regex would match one or more uppercase letters only if it is not followed by a closing curly } bracket. ^[A-Z]+(?!.*?})$ DEMO OR You could use perl regex verbs, {.*?}(*SKIP)(*F)|[A-Z]+ DEMO 回答2: try this pattern [A-Z]+(?![^}{]*}) Demo 回答3: Try this pattern: {.*?}|([A-Z]+) Then test group1 if

Regular Expression for paired brackets

北慕城南 提交于 2020-01-15 05:50:09
问题 The Input Line goes like this (just a part of it): [[Text Text Text]][[text text text]]asdasdasdasda[[asdasdasdasd]] What I want is to list all matches wherein text enclosed in a pair of [[ and ]] . I did try several patterns, but all fails when a unclosed [[ or ]] is within the input line. For example: [[text[[text text TEXT text]] Also, what if a single bracket exist within the input line, like: [[text [text] text TEXT text]] The regex pattern I used was: \[\[[^\[\[]*\]\] 回答1: \[\[(?:(?!\[\

Using regex to match non-word characters BUT NOT smiley faces

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 17:04:40
问题 I have a Java program which is supposed to remove all non-letter characters from a string, except when they are a smiley face such as =) or =] or :P It's very easy to match the opposite with [a-zA-Z ]|=\)|=\]|:P but I cannot figure out how to negate this expression. Since I am using the String.replaceAll() function it must be in the negated form. I believe part of the issue may come from the fact that smiles are generally 2 characters long, and I am only matching 1 character at a time?

Regex : Remove all commas between a quote separated string [python]

依然范特西╮ 提交于 2020-01-11 11:47:50
问题 What would be an appropriate regex to remove all commas in a string as such: 12, 1425073747, "test", "1, 2, 3, ... " Result: 12, 1425073747, "test", "1 2 3 ... " What I have that matches correctly: "((\d+), )+\d+" However, I obviously cant replace this with $1 $2. I can't use "\d+, \d+" because it will match 12, 1425073747 which is not what I want. If someone can explain how to recursively parse out values that would be appreciated as well. 回答1: This should work for you: >>> input = '12,

C# Regex to match a string that doesn't contain a certain string?

99封情书 提交于 2020-01-09 13:11:06
问题 I want to match any string that does not contain the string "DontMatchThis". What's the regex? 回答1: try this: ^(?!.*DontMatchThis).*$ 回答2: The regex to match a string that does not contain a certain pattern is (?s)^(?!.*DontMatchThis).*$ If you use the pattern without the (?s) (which is an inline version of the RegexOptions.Singleline flag that makes . match a newline LF symbol as well as all other characters), the DontMatchThis will only be searched for on the first line, and only a string

Regular Expression to exclude set of Keywords

六眼飞鱼酱① 提交于 2020-01-09 03:01:25
问题 I want an expression that will fail when it encounters words such as "boon.ini" and "http". The goal would be to take this expression and be able to construct for any set of keywords. 回答1: ^(?:(?!boon\.ini|http).)*$\r?\n? (taken from RegexBuddy's library) will match any line that does not contain boon.ini and/or http. Is that what you wanted? 回答2: An alternative expression that could be used: ^(?!.*IgnoreMe).*$ ^ = indicates start of line $ = indicates the end of the line (?! Expression) =

Regex match all url except youtube ones

霸气de小男生 提交于 2020-01-06 08:45:10
问题 I am sure this is a trivial questions for you genii here. I seem to be stuck I have a couple of links to process and I want to convert all links to hyperlinks and youtube links to youtube videos. I have everything working. I just need to figure out how to regex out all links EXCEPT youtube ones. Here is an example of my regex: http://gskinner.com/RegExr/?2u7g4 thanks. Help please. 回答1: I would use the regex: /(http:\/\/)?(www\.)?youtube.com\S*/ to match youtube links. Or did you mean you

Using Servlet filter on all the pages except the index

喜你入骨 提交于 2020-01-06 02:43:51
问题 I'm trying to use a Filter to force my users to login if they want to access some pages. So my Filter has to redirect them to an error page in there's no session. But I don't want this to happen when they visit index.html , because they can login in the index page. So I need an URL Pattern that matches all the pages excluding / and index.xhtml . How can I do that? Can I use regex in my web.xml ? EDIT: After reading this I thought that I can make something like : if (!req.getRequestURI()