regex-negation

Regular expression that only matches internal Markdown links without .md extension

杀马特。学长 韩版系。学妹 提交于 2019-12-24 18:13:28
问题 I have a project with lots of Markdown files that include internal and external (start with http ) links. Some of these internal links don't have a .md file extension and so don't work when rendered outside of Jekyll. Examples: [link text 1](internal-link) [link text 2](internal-link-2.md) [link text 3](http://external-link...) I am looking for a regular expression that only matches the first of these three cases - internal link without .md file extension. 回答1: After refining, this could be

find pattern for url with no ending slash

不打扰是莪最后的温柔 提交于 2019-12-24 14:03:12
问题 I'm looking for preg_match_all pattern to find all URL on a page that don't have trailing slash. For example: if I have a href="/testing/abc/">end with slash a href="/testing/test/mnl">no ending slash The result would be #2 Thanks. 回答1: Better extract all your href links using DOM parser and see if URL is ending with slash or not. No regex needed for that. For the regex solution for the examples provided you can use this regex: /href=(['"])[^\s]+(?<!\/)\1/ Live Demo: http://www.rubular.com/r

Vim folding every line ending in { but not classes

扶醉桌前 提交于 2019-12-24 08:51:16
问题 I intend to fold all the lines ending in { but not classes. So far I have came up with this command : :%g/.\{-}\(class\)\@!.*{$/normal! zf% But this would match also the lines containing class . 回答1: There are several problems: From :help /\@! : "You can't use "\@!" to look for a non-match before the matching position". Use \@<! , include the possible characters in between in there, and drop the useless (because it's not anchored) non-greedy first match. The :global command places the cursor

Regular Expression Searching Matching One Word but Not Another

天涯浪子 提交于 2019-12-24 06:42:04
问题 <ReportExport ID="export1" runat="server" AlertNoTests="false" PDFPageOrientation="Portrait" HideExcel="true" OnPDFClicked="CreatePDF" AllowPDFOptions="true" HideBulkPDFOptions="false" HideOrientation="true" HidePaperSize="true" MaxReportsAtOnce="250" HideTextExport="true" /> I'm trying to use Visual Studio's find feature using regular expressions to find ReportExport in my entire solution where the HideTextExport property is not being set. This is only ever defined in the markup once on a

Regex: Negating characters

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 02:20:57
问题 quick question - How do you create a language of strings out of say {x,y}, but negating all strings with (xy)? My attempt's so far: \bx*[^(xy)]*y\b OR \by*[^(xy)]*x\b OR \b[^(xy)][xy]*[^(xy)]*\b The last of which is the least restricted, but seems clumsy with the multiple usage of [^(xy)]. What is the laziest most convenient method for completely negating a string which contains (xy), but allows all other combinations? Thanks Editted: Example strings that are allowed: xxxxxxx yyyyyyyyy yxxxx

Why is negation of a regex needed?

放肆的年华 提交于 2019-12-24 00:58:52
问题 There are so many questions on regex-negation here on SO. I am not sure I understand why people feel the need to negate a regex. Why not use something like grep -v that shows only the results that do not match the regex? $ ls april august december february january july june march may november october september $ ls | grep ber december november october september $ ls | grep -v ber april august february january july june march may 回答1: Probably because grep isn't the only place that regexes are

Help With Particular Regular Expression - Not Containing Some String

倾然丶 夕夏残阳落幕 提交于 2019-12-23 10:36:11
问题 How do I say, in regular expressions: Any portion of a string beginning with a capital letter, containing at least one space character, not containing the string " _ " (space underscore space), and ending with the string "!!!" (without the quotes)? I am having trouble with the "not containing" part. Here is what I have so far: [A-Z].* .*!!! How do I modify this to also specify "Not containing ' _ '"? It does not need to be the specific string " _ ". How can I say "not containing" ANY string?

PHP Regexp negative lookahead

ぃ、小莉子 提交于 2019-12-23 08:48:01
问题 I'm trying match all words wrapped with { } but not the words with "_loop". I can't see where I'm going wrong with my reg expression. $content = '<h1>{prim_practice_name}</h1><p>{prim_content}</p><p>Our Locations Are {location_loop}{name} - {state}<br/>{/location_loop}</p>'; $pattern = '/\{(\w*(?!\_loop))\}/'; 回答1: This happens because \w* "eats" the stopping word "_loop" before your check, to prevent that you should check the word first (before \w*), like the following: $pattern = '/\{((?!\w

Regex to find numbers excluding four digit numbers

南楼画角 提交于 2019-12-23 03:18:09
问题 I am trying to figure out how to find numbers that are not years (I'm defining a year as simply a number that is four digits wide.) For example, I want to pick up 1 12 123 But NOT 1234 in order to avoid dates (4 digits). if the regex also picked up 12345 that is fine, but not necessary for solving this problem (Note: these requirements may seem odd. They are part of a larger solution that I am stuck with) 回答1: If lookbehind and lookahead are available, the following should work: (?<!\d)(\d{1

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