{"id":1936,"date":"2021-03-08T10:39:53","date_gmt":"2021-03-08T15:39:53","guid":{"rendered":"http:\/\/www.insidethe.com\/blog\/?p=1936"},"modified":"2021-03-08T10:39:53","modified_gmt":"2021-03-08T15:39:53","slug":"regex-to-find-lines-containing-text-and-exclude-matches-containing-text","status":"publish","type":"post","link":"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/","title":{"rendered":"RegEx To Find Lines Containing Text and Exclude Matches Containing Text"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>This is an example of how to do a find in files with PhpStorm or WebStorm but exclude lines matching a specific string.<\/p>\n<p>For example, give this code below, we want to find all lines that contain the http:\/\/example.com\/api but do not also contain the string &#8216;some_variable&#8217;<\/p>\n<pre>$my_url = variable_get(\"some_variable\", \"http:\/\/example.com\/api\");\r\n...\r\n$my_url = 'http:\/\/example.com\/api';<\/pre>\n<p>The RegEx pattern will find all lines that contain the URL but exclude the lines with the specified text:<\/p>\n<pre>^(?!.*some_variable.*$).*(http:\\\/\\\/example.com\\\/api)<\/pre>\n<p>This should work in any JetBrains editor which supports Java regular expressions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; This is an example of how to do a find in files with PhpStorm or WebStorm but exclude lines matching a specific string. For example, give this code below, we want to find all lines that contain the http:\/\/example.com\/api but do not also contain the string &#8216;some_variable&#8217; $my_url = variable_get(&#8220;some_variable&#8221;, &#8220;http:\/\/example.com\/api&#8221;); &#8230; $my_url = [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>RegEx To Find Lines Containing Text and Exclude Matches Containing Text - Insidethe.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RegEx To Find Lines Containing Text and Exclude Matches Containing Text - Insidethe.com\" \/>\n<meta property=\"og:description\" content=\"&nbsp; This is an example of how to do a find in files with PhpStorm or WebStorm but exclude lines matching a specific string. For example, give this code below, we want to find all lines that contain the http:\/\/example.com\/api but do not also contain the string &#8216;some_variable&#8217; $my_url = variable_get(&quot;some_variable&quot;, &quot;http:\/\/example.com\/api&quot;); ... $my_url = [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/\" \/>\n<meta property=\"og:site_name\" content=\"Insidethe.com\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-08T15:39:53+00:00\" \/>\n<meta name=\"author\" content=\"Jared\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jared\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/\",\"url\":\"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/\",\"name\":\"RegEx To Find Lines Containing Text and Exclude Matches Containing Text - Insidethe.com\",\"isPartOf\":{\"@id\":\"https:\/\/insidethe.com\/blog\/#website\"},\"datePublished\":\"2021-03-08T15:39:53+00:00\",\"dateModified\":\"2021-03-08T15:39:53+00:00\",\"author\":{\"@id\":\"https:\/\/insidethe.com\/blog\/#\/schema\/person\/046e8441af869a735c4e31ac51541a99\"},\"breadcrumb\":{\"@id\":\"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/insidethe.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"RegEx To Find Lines Containing Text and Exclude Matches Containing Text\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/insidethe.com\/blog\/#website\",\"url\":\"https:\/\/insidethe.com\/blog\/\",\"name\":\"Insidethe.com\",\"description\":\"It is my space, but better than myspace\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/insidethe.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/insidethe.com\/blog\/#\/schema\/person\/046e8441af869a735c4e31ac51541a99\",\"name\":\"Jared\",\"sameAs\":[\"https:\/\/www.insidethe.com\/blog\"],\"url\":\"https:\/\/insidethe.com\/blog\/author\/jared\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"RegEx To Find Lines Containing Text and Exclude Matches Containing Text - Insidethe.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/","og_locale":"en_US","og_type":"article","og_title":"RegEx To Find Lines Containing Text and Exclude Matches Containing Text - Insidethe.com","og_description":"&nbsp; This is an example of how to do a find in files with PhpStorm or WebStorm but exclude lines matching a specific string. For example, give this code below, we want to find all lines that contain the http:\/\/example.com\/api but do not also contain the string &#8216;some_variable&#8217; $my_url = variable_get(\"some_variable\", \"http:\/\/example.com\/api\"); ... $my_url = [&hellip;]","og_url":"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/","og_site_name":"Insidethe.com","article_published_time":"2021-03-08T15:39:53+00:00","author":"Jared","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jared","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/","url":"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/","name":"RegEx To Find Lines Containing Text and Exclude Matches Containing Text - Insidethe.com","isPartOf":{"@id":"https:\/\/insidethe.com\/blog\/#website"},"datePublished":"2021-03-08T15:39:53+00:00","dateModified":"2021-03-08T15:39:53+00:00","author":{"@id":"https:\/\/insidethe.com\/blog\/#\/schema\/person\/046e8441af869a735c4e31ac51541a99"},"breadcrumb":{"@id":"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/insidethe.com\/blog\/2021\/03\/regex-to-find-lines-containing-text-and-exclude-matches-containing-text\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/insidethe.com\/blog\/"},{"@type":"ListItem","position":2,"name":"RegEx To Find Lines Containing Text and Exclude Matches Containing Text"}]},{"@type":"WebSite","@id":"https:\/\/insidethe.com\/blog\/#website","url":"https:\/\/insidethe.com\/blog\/","name":"Insidethe.com","description":"It is my space, but better than myspace","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/insidethe.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/insidethe.com\/blog\/#\/schema\/person\/046e8441af869a735c4e31ac51541a99","name":"Jared","sameAs":["https:\/\/www.insidethe.com\/blog"],"url":"https:\/\/insidethe.com\/blog\/author\/jared\/"}]}},"_links":{"self":[{"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/posts\/1936"}],"collection":[{"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/comments?post=1936"}],"version-history":[{"count":1,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/posts\/1936\/revisions"}],"predecessor-version":[{"id":1937,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/posts\/1936\/revisions\/1937"}],"wp:attachment":[{"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/media?parent=1936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/categories?post=1936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/insidethe.com\/blog\/wp-json\/wp\/v2\/tags?post=1936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}