regex-lookarounds

Javascript regex negative lookbehind not working in firefox

江枫思渺然 提交于 2019-11-27 15:34:07
I need to modify the following javascript regex because the negative lookbehind in it throws an error in firefox: content = content.replace(/(?![^<]*>)(?:[\"])([^"]*?)(?<!=)(?:[\"])(?!>)/g, '„$1“'); Does anyone have an idea and can help me out? Thanks in advance! Lookbehinds are only available in browsers supporting ECMA2018 standard, and that means, only the latest versions of Chrome can handle them. To support the majority of browsers, convert your pattern to only use lookaheads. The (?<!=) negative lookbehind makes sure there is no = immediately to the left of the current location. [^"] is

What are the differences between perl and java regex capabilities?

萝らか妹 提交于 2019-11-27 15:28:12
What are the differences between perl and java with regard to what regular expression terms are supported? This question is isolated to just the regular expressions, and specifically excludes differences in how regex can be used - ie the functions/methods available that use regex - and syntactic differences between the languages such as the java requirement to escape backslashes etc. Of particular interest is the partial/occasional support java has for variable length look-behinds. Rohit Jain The "Comparison to Perl 5" section of java.util.regex.Pattern lists many differences. For example,

What's wrong with my lookahead regex in GNU sed?

人盡茶涼 提交于 2019-11-27 07:11:49
This is what I'm doing (simplified example): gsed -i -E 's/^(?!foo)(.*)$/bar\1/' file.txt I'm trying to put bar in front of every line that doesn't start with foo . This is the error: gsed: -e expression #1, char 22: Invalid preceding regular expression What's wrong? As far as I know sed has not neither look-ahead nor look-behind. Switch to a more powerful language with similar syntax, like perl . kkeller sed -i '/^foo/! s/^/bar/' file.txt -i change the file in place /^foo/! only perform the next action on lines not ! starting with foo ^foo s/^/bar/ change the start of the line to bar You use

Regex to get the words after matching string

拈花ヽ惹草 提交于 2019-11-27 00:35:12
Below is the Content: Subject: Security ID: S-1-5-21-3368353891-1012177287-890106238-22451 Account Name: ChamaraKer Account Domain: JIC Logon ID: 0x1fffb Object: Object Server: Security Object Type: File Object Name: D:\ApacheTomcat\apache-tomcat-6.0.36\logs\localhost.2013-07-01.log Handle ID: 0x11dc I need to capture the words after the Object Name: word in that line. Which is D:\ApacheTomcat\apache-tomcat-6.0.36\logs\localhost.2013-07-01.log . I hope somebody can help me with this. ^.*\bObject Name\b.*$ matches - Object Name The following should work for you: [\n\r].*Object Name:\s*([^\n\r]*

Regex Until But Not Including

柔情痞子 提交于 2019-11-26 23:33:06
For regex what is the syntax for search until but not including? Kinda like: Haystack: The quick red fox jumped over the lazy brown dog Expression: .*?quick -> and then everything until it hits the letter "z" but do not include z The explicit way of saying "search until X but not including X " is: (?:(?!X).)* where X can be any regular expression. In your case, though, this might be overkill - here the easiest way would be [^z]* This will match anything except z and therefore stop right before the next z . So .*?quick[^z]* will match The quick fox jumps over the la . However, as soon as you

Regex for existence of some words whose order doesn't matter

穿精又带淫゛_ 提交于 2019-11-26 20:47:12
I would like to write a regex for searching for the existence of some words, but their order of appearance doesn't matter. For example, search for "Tim" and "stupid". My regex is Tim.*stupid|stupid.*Tim . But is it possible to write a simpler regex (e.g. so that the two words appear just once in the regex itself)? Unihedron See this regex: /^(?=.*Tim)(?=.*stupid).+/ Regex explanation: ^ Asserts position at start of string. (?=.*Tim) Asserts that "Tim" is present in the string. (?=.*stupid) Asserts that "stupid" is present in the string. .+ Now that our phrases are present, this string is valid

Negative lookahead Regular Expression

て烟熏妆下的殇ゞ 提交于 2019-11-26 19:49:38
I want to match all strings ending in ".htm" unless it ends in "foo.htm". I'm generally decent with regular expressions, but negative lookaheads have me stumped. Why doesn't this work? /(?!foo)\.htm$/i.test("/foo.htm"); // returns true. I want false. What should I be using instead? I think I need a "negative look behind " expression (if JavaScript supported such a thing, which I know it doesn't). The problem is pretty simple really. This will do it: /^(?!.*foo\.htm$).*\.htm$/i What you are describing (your intention) is a negative look-behind , and Javascript has no support for look-behinds.

Regex lookahead for 'not followed by' in grep

老子叫甜甜 提交于 2019-11-26 19:47:55
I am attempting to grep for all instances of Ui\. not followed by Line or even just the letter L What is the proper way to write a regex for finding all instances of a particular string NOT followed by another string? Using lookaheads grep "Ui\.(?!L)" * bash: !L: event not found grep "Ui\.(?!(Line))" * nothing Negative lookahead, which is what you're after, requires a more powerful tool than the standard grep . You need a PCRE-enabled grep. If you have GNU grep , the current version supports options -P or --perl-regexp and you can then use the regex you wanted. If you don't have (a

Regex negative lookbehind not valid in JavaScript

拜拜、爱过 提交于 2019-11-26 19:09:22
Consider: var re = /(?<=foo)bar/gi; It is an invalid regular expression in Plunker. Why? JavaScript lacks support for lookbehinds like (?<=…) (positive) and (?<!…) (negative), but that doesn't mean you can't still implement this sort of logic in JavaScript. Matching (not global) Positive lookbehind match: // from /(?<=foo)bar/i var matcher = mystring.match( /foo(bar)/i ); if (matcher) { // do stuff with matcher[1] which is the part that matches "bar" } Fixed width negative lookbehind match: // from /(?<!foo)bar/i var matcher = mystring.match( /(?!foo)(?:^.{0,2}|.{3})(bar)/i ); if (matcher) { /

Regex expression not working with once or none

泪湿孤枕 提交于 2019-11-26 18:41:00
问题 Below is my regex: [^4\d{3}-?\d{4}-?\d{4}-?\d{4}$] But it throws an error at - . I am using ? , which should allows - to appear zero or one time. Why it is giving errors? 回答1: The problem with the regex is that the pattern is enclosed with [ and ] that are treated as character class markers (see Character Classes or Character Sets): With a "character class", also called "character set", you can tell the regex engine to match only one out of several characters. Simply place the characters you