regex-lookarounds

Parsing regex with alternatives and optionals

╄→尐↘猪︶ㄣ 提交于 2019-12-24 03:37:08
问题 I'm building a chatbot subset of RiveScript and trying to build the pattern matching parser with regular expression. Which three regexes match the following three examples? ex1: I am * years old valid match: - "I am 24 years old" invalid match: - "I am years old" ex2: what color is [my|your|his|her] (bright red|blue|green|lemon chiffon) * valid matches: - "what color is lemon chiffon car" - "what color is my some random text till the end of string" ex3: [*] told me to say * valid matches: -

Regex negative lookahead

南笙酒味 提交于 2019-12-23 09:59:07
问题 I need to modify this regex href=\"(.*)\" which matches this... href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306" To NOT match this... href="./pothole_locator_map.aspx?lang=en-gb&lat=53.153977&lng=-3.533306&returnurl=AbandonedVehicles.aspx" Tried this, but with no luck href=\"(.*)\"(?!&returnurl=AbandonedVehicles.aspx) Any help would be much appreciated. Thanks, Al. 回答1: Lookaheads should be placed before the string is consumed by matching, i.e. href=\"(?!.*&returnurl

Scala regex multiline match with negative lookahead

空扰寡人 提交于 2019-12-23 06:01:29
问题 I'm writing a DSL using Scala's parser combinators. I have recently changed my base class from StandardTokenParsers to JavaTokenParsers to take advantage of the regex features I think I need for one last piece of the puzzle. (see Parsing a delimited multiline string using scala StandardTokenParser) What I am trying to do is to extract a block of text delimited by some characters ( {{ and }} in this example). This block of text can span multiple lines. What I have so far is: def docBlockRE =

Scala regex multiline match with negative lookahead

帅比萌擦擦* 提交于 2019-12-23 06:01:03
问题 I'm writing a DSL using Scala's parser combinators. I have recently changed my base class from StandardTokenParsers to JavaTokenParsers to take advantage of the regex features I think I need for one last piece of the puzzle. (see Parsing a delimited multiline string using scala StandardTokenParser) What I am trying to do is to extract a block of text delimited by some characters ( {{ and }} in this example). This block of text can span multiple lines. What I have so far is: def docBlockRE =

Regex to match all non-digit characters which are interspersed with digits with SQL

限于喜欢 提交于 2019-12-23 05:40:08
问题 Using SQL Anywhere 16 regex (Perl 5 equivalent) I would like to match all non-digit characters in the following string: This 100 is 2 a 333 test. such that the match results in This is a test. I have a feeling this requires lookarounds but I'm not sure of the exact syntax. Some of my failed attempts: \D* matches This \D*(?=\d) matches This (\D*(?=\d*)|(?<=\d)\D*)* matches This 来源: https://stackoverflow.com/questions/36020273/regex-to-match-all-non-digit-characters-which-are-interspersed-with

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

别来无恙 提交于 2019-12-23 02:42:07
问题 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. 回答1: If you want to delete text other than 14 digits

Need a breakdown of the following regular expression

冷暖自知 提交于 2019-12-23 01:57:28
问题 I have some trouble understanding how the following regular expression is working. ,(?=([^\"]*\"[^\"]*\")*[^\"]*$) The expression basically matches all the commas that are NOT enclosed in quotes. For example: apple, banana, pineapple, "tropical fruits like mango, guava, key lime", peaches Will be split into: apple banana pineapple "tropical fruits like mango, guava, key lime" peaches Can someone provide me with a good breakdown of the expression? I don't understand how positive look-ahead is

Regular Expressions with lookahead in Ruby

拟墨画扇 提交于 2019-12-23 01:28:11
问题 My current regex battle is replacing all commas before a number in a string. The regex must then ignore all following commas. I've been screwing around on rubular for about an hour and can't quite seem to get something working. Test String... 'this is, a , sentence33 Here, is another.' Desired Output... 'this is comma a comma sentence33 Here, is another.' So something along the lines of... testString.gsub(/\,*\d\d/,"comma") To give you some background, I'm doing a little scraping sideproject.

Regex to match whatsapp chat log

99封情书 提交于 2019-12-22 17:58:01
问题 I've been trying to create Regex for WhatsApp chat log. So far I've been able to achieve this Click Here for the test link By creating the following Regex: (?P<datetime>\d{2}\/\d{2}\/\d{4},\s\d(?:\d)?:\d{2} [pa].m.)\s-\s(?P<name>[^:]*):(?P<message>.*) The problem with this regex is, it is not able to match big messages which span multiple lines with line breaks. You can see the issue in the link provided above. Help would be appreciated. Thank you. 回答1: There you go: ^ (?P<datetime>\d{2}/\d{2

python regex match more than once per index of search string

时间秒杀一切 提交于 2019-12-22 13:48:39
问题 I'm looking for a way to make the finditer function of the python re module or the newer regex module to match all possible variations of a particular pattern, overlapping or otherwise. I am aware of using lookaheads to get matches without consuming the search string, but I still only get one regex per index, where I could get more than one. The regex I am using is something like this: (?=A{2}[BA]{1,6}A{2}) so in the string: AABAABBAA it should be able to match: AABAA AABAABBAA AABBAA but