regex-negation

Regex removing anything that is not a 14-digit number followed with space

三世轮回 提交于 2019-12-08 04:55:24
I'm trying to invert this expression: ([0-9]{14} ) , so all 14 digit numbers followed by a space. I looked everywhere, and it seems that the best way should be using negative lookahead . But when I try apply q(?!u) to my case >> (?!([0-9]{14} )) , it doesn't work. What am I doing wrong? I will appreaciate any advice, thank you. The point is to remove everything that is not a 14-digit chunk of text while preserving those 14-digit chunks. If you want to delete text other than 14 digits followed with a space, use (\b\d{14} )|. and replace with $1 . The pattern matches and captures (we can refer

Splitting string into matching and non-matching groups in javascript

扶醉桌前 提交于 2019-12-08 00:57:58
问题 I am trying to split the string into an array of strings those matching a regular expression and those that don't: string = "Lazy {{some_animal}} jumps over.." # do some magic with regex /({{\s?[\w]+\s?}})/g and its negation array = ["Lazy ", "{{some_animal}}", " jumps over.."] Best performant way to do that in javascript? 回答1: You can use String match for that The regex below simply matches anything that's not a mustach, optionally surrounded by mustaches. Example snippet: var str = "Lazy {

Rewrite regex without negation

放肆的年华 提交于 2019-12-07 22:20:25
问题 I have wrote this regex to help me extract some links from some text files: https?:\/\/(?:.(?!https?:\/\/))+$ Because I am using golang/regexp lib, I'm not able to use it, due to my negation (?!.. What I would like to do with it, is to select all the text from the last occurance of http/https till the end. sometextsometexhttp://websites.com/path/subpath/#query1sometexthttp://websites.com/path/subpath/#query2 => Output: http://websites.com/path/subpath/#query2 Can anyone help me with a

Regex Query Help - Lookbehind

。_饼干妹妹 提交于 2019-12-07 15:28:06
问题 This is somewhat related to: Regular Expression - Formatting text in a block - IM but a different problem. Looking for - 's wrapping text with the following conditions: Conditions: token can be at start or end of line token must be surround by space or one or more symbols: {.,!@#$....}. must not be a normal character [a-zA-Z] surrounding the - pair in question. See Sample test 3 ...w-thank you- Test 4 and 5 succeed because the - is wrapped with [^a-zA-Z] token must not be followed by a space

Regex match everything between two {}

跟風遠走 提交于 2019-12-07 11:41:48
问题 I was looking at different answers here but unfortunately none of them was good for my case. So I hope you don't mind about it. So I need to match everything between two curly brackets {} except situation when match starts with @ and without these curly brackets e.g: "This is a super text { match_this }" "{ match_this }" "This is another example @{deal_with_it}" Here are my test strings, 1,2,3 are valid while the last one shouldn't be: 1 {eww} 2 r23r23{fetwe} 3 #{d2dded} 4 @{d2dded} I was

Regex negative match query

岁酱吖の 提交于 2019-12-07 08:20:11
问题 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 回答1: 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. 回答2: You

POSIX Regular Expressions: Excluding a word in an expression?

谁说我不能喝 提交于 2019-12-07 06:52:07
问题 I am trying to create a regular expression using POSIX (Extended) Regular Expressions that I can use in my C program code. Specifically, I have come up with the following, however, I want to exclude the word "http" within the matched expressions. Upon some searching, it doesn't look like POSIX makes it obvious for catching specific strings. I am using something called a "negative look-a-head" in the below example (i.e. the (?!http:) ). However, I fear that this may only be something available

Regex to restrict UPPERCASE only

随声附和 提交于 2019-12-07 06:47:53
问题 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! 回答1: [^A-Z] Simply

Regex to find numbers excluding four digit numbers

余生长醉 提交于 2019-12-07 05:03:24
I am trying to figure out how to find numbers that are not years (I'm defining a year as simply a number that is four digits wide.) For example, I want to pick up 1 12 123 But NOT 1234 in order to avoid dates (4 digits). if the regex also picked up 12345 that is fine, but not necessary for solving this problem (Note: these requirements may seem odd. They are part of a larger solution that I am stuck with) If lookbehind and lookahead are available, the following should work: (?<!\d)(\d{1,3}|\d{5,})(?!\d) Explanation: (?<!\d) # Previous character is not a digit (\d{1,3}|\d{5,}) # Between 1 and 3

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

柔情痞子 提交于 2019-12-06 20:06:13
问题 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. 回答1: 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.