regex-negation

Regex negative match query

好久不见. 提交于 2019-12-05 12:33:38
I've got a regex issue, I'm trying to ignore just the number '41', I want 4, 1, 14 etc to all match. I've got this [^\b41\b] which is effectively what I want but this also ignores all single iterations of the values 1 and 4. As an example, this matches "41", but I want it to NOT match: \b41\b Try something like: \b(?!41\b)(\d+) The (?!...) construct is a negative lookahead so this means: find a word boundary that is not followed by "41" and capture a sequence of digits after it. You could use a negative look-ahead assertion to exclude 41 : /\b(?!41\b)\d+\b/ This regular expression is to be

Regex to restrict UPPERCASE only

夙愿已清 提交于 2019-12-05 12:18:51
I am stil struggling with understanding how Regex works exactly. I am getting usernames and they are in this format: firstname.lastname Both names may contain special international characters and they may contain an ' or - but I just need to detect if they contain any uppercase letters so I can throw an exception. I am using this expression [^A-Z].[^A-Z] It seems to me that this should work, I just don't understand why it doesn't. I hope somebody could explain. Thanks! [^A-Z] Simply means any character that isn't a capital A through capital Z. . Means any character you should be using \. As

Regex to match . (periods marking end of sentences) but not Mr. (as in Mr. Hopkins)

99封情书 提交于 2019-12-05 01:19:43
I'm trying to parse a text file into sentences ending in periods, but names like Mr. Hopkins are throwing false alarms on matching for periods. What regex identifies "." but not "Mr." For bonus, I'm also using ! to find end of sentences, so my current Regex is /(!/./ and I'd love an answer that incorporates my !'s too. Use negative look behind . (?<!Mr|Mrs|Dr|Ms)\. This will match a period only if it does not come after Mr , Mrs , Dr or Ms <? $str = "This is Mr. Someone and Mrs. Somebody. They are here to meet Dr. SomeoneElse."; $str = preg_replace("/(?<!Mr|Mrs|Dr|Ms)\\./", "\n", $str); echo(

XML Schema (XSD) 1.0 xs:pattern regex to match 4 digits as a string?

天涯浪子 提交于 2019-12-04 21:15:12
How can I match a specific sequence of digits as if it were a string in an XML Schema xs:pattern ? Say I have some tags containing arbitrary 10-character strings like <string>12345678990</string> And I want to rule out all tags with a specific blacklist of arbitrary sequences like 1234 , 2435 , ``9587`, or some such. How do I address the specific 4-digit sub-string in order to negate it and add it to a list of xs:pattern restrictions for <string> 's content model? I don't think there is any practical XSD-compliant regular expression that will match all strings except those containing "1234" as

how to replace plain url with hyperlinks in html doc

我的未来我决定 提交于 2019-12-04 20:06:10
I am trying to replace plain link to hyperlink in an html document. and my logic is private static final Pattern WEB_URL_PROTOCOL = Pattern.compile("(?i)http|https://"); StringBuffer sb = new StringBuffer(); if (text != null) { // Escape any inadvertent HTML in the text message text = EmailHtmlUtil.escapeCharacterToDisplay(text); // Find any embedded URL's and linkify Matcher m = Patterns.WEB_URL.matcher(text); while (m.find()) { int start = m.start(); if (start == 0 || text.charAt(start - 1) != '@') { String url = m.group(); Matcher proto = WEB_URL_PROTOCOL.matcher(url); String link; if

Regex to match keyword if not enclosed by curly braces

送分小仙女□ 提交于 2019-12-04 19:13:22
In a PHP variable I have some text that contains some keywords. These keywords are currently capitalised. I would like them to remain capitalised and be wrapped in curly brackets but once only. I am trying to write upgrade code but each time it runs it wraps the keywords in another set of curly brackets. What REGEX do I need to use to match the keyword alone without also matching it if it is {KEYWORD}. For example, the text variable is: $string = "BLOGNAME has posted COUNT new item(s), TABLE POSTTIME AUTHORNAME You received this e-mail because you asked to be notified when new updates are

What is wrong with my regex Pattern to find recurring cycles in Python?

血红的双手。 提交于 2019-12-04 12:15:37
I want to match any string that has a recurring cycle. Like in this data: 3333333333333333333333333333333333333333 / 1 digit cycle(3) 1666666666666666666666666666666666666666 / 1 digit cycle(6) 1428571428571428571428571428571428571428 / 6 digit cycle(142857) 1111111111111111111111111111111111111111 / 1 digit cycle(1) 0909090909090909090909090909090909090909 / 2 digit cycle(09) 0834522467546323545411673445234655345222 / no cycle 0769230769230769230769230769230769230769 / 6 digit cycle(769230) 0714285714285714285714285714285714285714 / 6 digit cycle(714285)

RegEx to tell if a string does not contain a specific character

拟墨画扇 提交于 2019-12-04 08:49:25
问题 Easy question this time. I'm trying to test whether or not a string does not contain a character using regular expressions. I thought the expression was of the form "[^ x ]" where x is the character that you don't want to appear, but that doesn't seem to be working. For example, Regex.IsMatch("103","[^0]") and Regex.IsMatch("103&","[^&]") both return true (I would expect false). I started using "[^&]" and thought maybe the & needed to be escaped as \&, but it didn't seem to make a difference.

Python regex not to match http://

僤鯓⒐⒋嵵緔 提交于 2019-12-04 06:47:52
I am facing a problem to match and replace certain words, not contained in http:// Present Regex: http://.*?\s+ This matches the pattern http://www.egg1.com http://www.egg2.com I need a regex to match certain words contained outside the http:// Example: "This is a sample. http://www.egg1.com and http://egg2.com. This regex will only match this egg1 and egg2 and not the others contained inside http:// " Match: egg1 egg2 Replaced: replaced1 replaced2 Final Output : "This is a sample. http://www.egg1.com and http://egg2.com. This regex will only match this replaced1 and replaced2 and not the

how to negate any regular expression in Java

让人想犯罪 __ 提交于 2019-12-03 08:29:30
问题 I have a regular expression which I want to negate, e.g. /(.{0,4}) which String.matches returns the following "/1234" true "/12" true "/" true "" false "1234" false "/12345" false Is there a way to negate (using regx only) to the above so that the results are: "/1234" false "/12" false "/" false "" true "1234" true "/12345" true I'm looking for a general solution that would work for any regx without re-writing the whole regex. I have looked at the following How to negate the whole regex?