lookbehind

Pattern in lookbehind

一笑奈何 提交于 2019-12-20 03:23:10
问题 My question is related with lookbehinds , I want to find all the first numbers after the word "this", I have the following data: 188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978 Pattern: this is an example of a number \d+ Output: 188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example

Regular expression: matching words between white space

妖精的绣舞 提交于 2019-12-19 07:10:45
问题 Im trying to do something fairly simple with regular expression in python... thats what i thought at least. What i want to do is matching words from a string if its preceded and followed by a whitespace. If its at the beginning of the string there is no whitespace required before - if its at the end, dont't search for whitespace either. Example: "WordA WordB WordC-WordD WordE" I want to match WordA WordB WordE . I only came up with overcomplicated way of doing this... (?<=(?<=^)|(?<=\s))\w+(?

Javascript/RegExp: Lookbehind Assertion is causing a “Invalid group” error

纵饮孤独 提交于 2019-12-17 18:58:12
问题 I'm doing a simple Lookbehind Assertion to get a segment of the URL (example below) but instead of getting the match I get the following error: Uncaught SyntaxError: Invalid regular expression: /(?<=\#\!\/)([^\/]+)/: Invalid group Here is the script I'm running: var url = window.location.toString(); url == http://my.domain.com/index.php/#!/write-stuff/something-else // lookbehind to only match the segment after the hash-bang. var regex = /(?<=\#\!\/)([^\/]+)/i; console.log('test this url: ',

Does lookbehind work in sed?

浪子不回头ぞ 提交于 2019-12-17 16:13:00
问题 I created a test using grep but it does not work in sed . grep -P '(?<=foo)bar' file.txt This works correctly by returning bar . sed 's/(?<=foo)bar/test/g' file.txt I was expecting footest as output, but it did not work. 回答1: GNU sed does not have support for lookaround assertions. You could use a more powerful language such as Perl or possibly experiment with ssed which supports Perl-style regular expressions. perl -pe 's/(?<=foo)bar/test/g' file.txt 回答2: Note that most of the time you can

How to match the first word after an expression with regex?

旧巷老猫 提交于 2019-12-17 09:46:21
问题 For example, in this text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eu tellus vel nunc pretium lacinia. Proin sed lorem. Cras sed ipsum. Nunc a libero quis risus sollicitudin imperdiet. I want to match the word after 'ipsum'. 回答1: This sounds like a job for lookbehinds, though you should be aware that not all regex flavors support them. In your example: (?<=\bipsum\s)(\w+) This will match any sequence of letter characters which follows "ipsum" as a whole word followed by

Does lookaround affect which languages can be matched by regular expressions?

最后都变了- 提交于 2019-12-17 08:05:30
问题 There are some features in modern regex engines which allow you to match languages that couldn't be matched without that feature. For example the following regex using back references matches the language of all strings that consist of a word that repeats itself: (.+)\1 . This language is not regular and can't be matched by a regex that does not use back references. Does lookaround also affect which languages can be matched by a regular expression? I.e. are there any languages that can be

What's the technical reason for “lookbehind assertion MUST be fixed length” in regex?

旧街凉风 提交于 2019-12-17 05:04:13
问题 For example,the regex below will cause failure reporting lookbehind assertion is not fixed length : #(?<!(?:(?:src)|(?:href))=["\']?)((?:https?|ftp)://[^\s\'"<>()]+)#S Such kind of restriction doesn't exist for lookahead . 回答1: Lookahead and lookbehind aren't nearly as similar as their names imply. The lookahead expression works exactly the same as it would if it were a standalone regex, except it's anchored at the current match position and it doesn't consume what it matches. Lookbehind is a

R: workaround for variable-width lookbehind

送分小仙女□ 提交于 2019-12-14 02:16:41
问题 Given this vector: ba <- c('baa','aba','abba','abbba','aaba','aabba')' I want to change the final a of each word to i except baa and aba . I wrote the following line ... gsub('(?<=a[ab]b{1,2})a','i',ba,perl=T) but was told: PCRE pattern compilation error 'lookbehind assertion is not fixed length' at ')a' . I looked around a little bit and apparently R/Perl can only lookahead for a variable width, not lookbehind. Any workaround to this problem? Thanks! 回答1: You can use the lookbehind

Need variable width negative lookbehind replacement

瘦欲@ 提交于 2019-12-14 01:56:12
问题 I have looked at many questions here (and many more websites) and some provided hints but none gave me a definitive answer. I know regular expressions but I am far from being a guru. This particular question deals with regex in PHP. I need to locate words in a text that are not surrounded by a hyperlink of a given class. For example, I might have This <a href="blabblah" class="no_check">elephant</a> is green and this elephant is blue while this <a href="blahblah">elephant</a> is red. I would

How to check for odd numbers of backslashes in a regex using Javascript?

浪尽此生 提交于 2019-12-11 15:39:42
问题 I have recently asked a question regarding an error I have been getting using a RegExp constructor in Javascript with lookbehind assertion. What I want to do it, to check for a number input bigger than 5 preceded by an odd number of backslash, in other words, that is not preceded by an escaped backslash Here is an example. \5 // match ! \\5 // no match ! \\\5 // match! The Regex I found online is (?<!\\)(?:\\{2})*\\(?!\\)([5-9]|[1-9]\d) But the problem here is that (?<!\\) causes a problem