lookahead

Regex match pattern after positive look ahead

时间秒杀一切 提交于 2019-12-11 10:05:23
问题 I have a regex that is doing a positive lookahead. The positive lookahead relies on "cfu/ml" being present in the string but doesn not include it in the result. Here's the regex: ((((less|greater)\s*tha[nt]\s*)?[><]*[\d]+[\sx,.-]*)*)+(?=CFU\s?/\s?ML) Ex string: "100,000,000 x 85 x 9345 cfu/ml" Match1: "100,000,000 x 85 x 9345" That's working just fine, but trying to match anything after that positive lookahead is not working. What I'm trying to do is add another result capture group after the

regex in parenthesis at the beginning

醉酒当歌 提交于 2019-12-11 02:14:00
问题 I have a regex trying to divide questions by speciality. Say I have the following regex: (?P<speciality>[0-9x]+) It works fine for this question (correct match: 7) (7)Which of the following is LEAST to be considered as a risk factor for esophageal cancer?; And for this (correct match: 8 and 13) (8,13)30 year old woman with amenorrhea, low serum estrogen and high serum LH/FSH, the most likely diagnosis is: But not for this one (incorrect match: 20). First trimester spontaneous abortion (before

Lookahead in JavaScript regex

为君一笑 提交于 2019-12-10 20:19:40
问题 Using JavaScript, I am trying to replace an attribute inside an html tag, and have come up with this regex: /<\s*tag[^>]*(attr)=['"]{1,1}([^'"\s]*)['"]{1,1}/ig; This works. However, I want to be able to specify to look for the same type of quotation mark enclosing the attribute value. So, for example, I want to specify if this is the form <tag attr='data'> , to look in the SECOND quotation mark for the single one, not the double one. The inverse case, <tag attr="data"> would be similar; match

Perl Regex: How to remove quotes inside quotes from CSV line

亡梦爱人 提交于 2019-12-10 18:34:47
问题 I've got a line from a CSV file with " as field encloser and , as field seperator as a string. Sometimes there are " in the data that break the field enclosers. I'm looking for a regex to remove these " . My string looks like this: my $csv = qq~"123456","024003","Stuff","","28" stuff with more stuff","2"," 1.99 ","",""~; I've looked at this but I don't understand how to tell it to only remove quotes that are not at the beginning of the string not at the end of the string not preceded by a ,

Replace all “\” characters which are *not* inside “<code>” tags

二次信任 提交于 2019-12-10 16:25:52
问题 First things first: Neither this, this, this nor this answered my question. So I'll open a new one. Please read Okay okay. I know that regexes are not the way to parse general HTML. Please take note that the created documents are written using a limited, controlled HTML subset. And people writing the docs know what they're doing. They are all IT professionals! Given the controlled syntax it is possible to parse the documents I have here using regexes. I am not trying to download arbitrary

How can I require that at least two lookahead patterns match within one regex?

懵懂的女人 提交于 2019-12-07 14:30:01
问题 The following regex ensures a password contains at least one lowercase, one uppercase, one number, and one special character: ^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[^a-zA-Z0-9\s]).*$ That works. Building on this, I'd like to require that only two of these groups be fulfilled in order for a password to be valid. For example, these would be valid passwords: aaaaa5, BFEWREWRE77, #2ccc. Is there I way I can modify this regex to support this requirement? 回答1: You can do it like this: with spaces

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

房东的猫 提交于 2019-12-05 20:16:48
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? Interestingly, replaceAll("(?![Tt])[Oo]","") removes every occurrence of the letter O, even in the word "to."

Nested regex lookahead and lookbehind

南笙酒味 提交于 2019-12-05 18:28:51
问题 I am having problems with the nested '+'/'-' lookahead/lookbehind in regex. Let's say that I want to change the '*' in a string with '%' and let's say that '\' escapes the next character. (Turning a regex to sql like command ^^). So the string '*test*' should be changed to '%test%' , '\\*test\\*' -> '\\%test\\%' , but '\*test\*' and '\\\*test\\\*' should stay the same. I tried: (?<!\\)(?=\\\\)*\* but this doesn't work (?<!\\)((?=\\\\)*\*) ... (?<!\\(?=\\\\)*)\* ... (?=(?<!\\)(?=\\\\)*)\* ...

Regular Expression - Match all but first letter in each word in sentence

浪子不回头ぞ 提交于 2019-12-04 10:56:35
I've almost got the answer here, but I'm missing something and I hope someone here can help me out. I need a regular expression that will match all but the first letter in each word in a sentence. Then I need to replace the matched letters with the correct number of asterisks. For example, if I have the following sentence: There is an enormous apple tree in my backyard. I need to get this result: T**** i* a* e******* a**** t*** i* m* b*******. I have managed to come up with an expression that almost does that: (?<=(\b[A-Za-z]))([a-z]+) Using the example sentence above, that expression gives me

How to implement LOOP in a FORTH-like language interpreter written in C

孤街浪徒 提交于 2019-12-04 08:11:18
问题 I'm writing a simple stack-based language in C and was wondering how I should go about implementing a loop structure of some kind, and/or lookahead symbols. Since the code is a bit long for this page (over 200 lines) I've put it in a GitHub repository. EDIT: The main program is in file stack.c . EDIT: The code just takes in input in words , kind of like FORTH. It uses scanf and works left to right. Then it uses a series of if s and strcmp s to decide what to do. That's really it. 回答1: The