lookahead

C# Regex - only match if substring exists?

允我心安 提交于 2021-02-13 17:28:45
问题 Ok, so I think I've got a handle on negation - now what about only selecting a match that has a specified substring within it? Given: This is a random bit of information from 0 to 1. This is a non-random bit of information I do NOT want to match This is the end of this bit This is a random bit of information from 0 to 1. This is a random bit of information I do want to match This is the end of this bit And attempting the following regex: /(?s)This is a random bit(?:(?=This is a random).)*

Match a pattern only once

删除回忆录丶 提交于 2021-01-27 04:14:17
问题 I have a string foo-bar-bat.bla I wish to match only foo My flawed pattern matches both foo and bar \w+(?=-.*\.bla) How do I discard bar ? Or maybe even better, how could I stop matching stuff after foo ? 回答1: You could use the following pattern (as long as your strings are always formatted the way you said) : ^\w+(?=-.*\.bla) Edit live on Debuggex The ^ sign matches the beginning of the string. And thus will take the very first match of the string. The ?= is meant to make sure the group

Regex matching string containing at least x characters and x numbers

岁酱吖の 提交于 2020-01-30 06:34:46
问题 I have a requirement to test if string matches following rules: Has at least 8 [a-zA-Z!@#$%^&+=] characters and has at least 1 [0-9] number OR Has at least 8 [0-9] numbers and has at least 1 [a-zA-Z!@#$%^&+=] character So far I tried this: "^(?=(?=.*[a-zA-Z!@#$%^&+=].*[a-zA-Z!@#$%^&+=].*[a-zA-Z!@#$%^&+=].*[a-zA-Z!@#$%^&+=].*[a-zA-Z!@#$%^&+=].*[a-zA-Z!@#$%^&+=].*[a-zA-Z!@#$%^&+=].*[a-zA-Z!@#$%^&+=])(?=.*[0-9])|(?=.*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9])(?=.*[a-zA-Z!@#$%^&+=]))

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?

LR(1) Item DFA - Computing Lookaheads

喜欢而已 提交于 2020-01-11 16:40:09
问题 I have trouble understanding how to compute the lookaheads for the LR(1)-items. Lets say that I have this grammar: S -> AB A -> aAb | a B -> d A LR(1)-item is an LR(0) item with a lookahead. So we will get the following LR(0)-item for state 0: S -> .AB , {lookahead} A -> .aAb, {lookahead} A -> .a, {lookahead} State: 1 A -> a.Ab, {lookahead} A -> a. ,{lookahead} A -> .aAb ,{lookahead} A ->.a ,{lookahead} Can somebody explain how to compute the lookaheads ? What is the general approach ? Thank

How can I read different groups of data on the same InputStream, using different types of InputStreams for each of them?

坚强是说给别人听的谎言 提交于 2020-01-06 08:43:30
问题 I needed to save some data in Java in various ways, to a File , to a String , to System.out ... And I ended up with 3 methods doing pretty much the same thing. So I changed them into a single method with an OutputStream as a parameter. I wrote a few things to a single OutputStream, e.g. some text, a serialized object, another serialized object, some numerical data ... But now I'm stuck. I overlooked the fact that I cannot distinguish between the different things that have been written. I

Lookahead in Regex

时光怂恿深爱的人放手 提交于 2020-01-05 07:44:20
问题 I am trying to extract venue from a file which contains several articles using regex. I know that the venue starts with either For/From and is followed by date which starts with a day of the week or author's name if the date is missing, I wrote the following regex to match the venue, however it always matches everything till the author's name which means the date also comes in the venue if that article has a date. """((?<=\n)(?:(?:\bFrom\b)|(?:\bFor\b)).*?(?=(?:(?:Monday|Tuesday|Wednesday

Two very close regexes with lookahead assertions in Python - why does re.split() behave differently?

安稳与你 提交于 2020-01-05 02:59:44
问题 I was trying to anser this question where the OP has the following string: "path:bte00250 Alanine, aspartate and glutamate metabolism path:bte00330 Arginine and proline metabolism" and wants to split it to obtain the following list: ['path:bte00250 Alanine, aspartate and glutamate metabolism', 'path:bte00330 Arginine and proline metabolism'] I tried to solve it by using a simple lookahead assertion in a regex, (?=path:) . Well, it did not work: >>> s = "path:bte00250 Alanine, aspartate and

Two very close regexes with lookahead assertions in Python - why does re.split() behave differently?

扶醉桌前 提交于 2020-01-05 02:59:24
问题 I was trying to anser this question where the OP has the following string: "path:bte00250 Alanine, aspartate and glutamate metabolism path:bte00330 Arginine and proline metabolism" and wants to split it to obtain the following list: ['path:bte00250 Alanine, aspartate and glutamate metabolism', 'path:bte00330 Arginine and proline metabolism'] I tried to solve it by using a simple lookahead assertion in a regex, (?=path:) . Well, it did not work: >>> s = "path:bte00250 Alanine, aspartate and

Regex with negative lookahead across multiple lines

强颜欢笑 提交于 2019-12-29 08:48:11
问题 For the past few hours I've been trying to match address(es) from the following sample data and I can't get it to work: medicalHistory None address 24 Lewin Street, KUBURA, NSW, Australia email MaryBeor@spambob.com address 16 Yarra Street, LAWRENCE, VIC, Australia name Mary Beor medicalHistory None phone 00000000000000000000353336907 birthday 26-11-1972 My plan was to find anything that starts with "address", is followed by any space followed by characters, numbers commas and newlines and