recentpopularlog in

kme : patternmatching   33

GitHub - tomnomnom/gron: Make JSON greppable!
gron - Make JSON greppable!

gron transforms JSON into discrete assignments to make it easier to grep for what you want and see the absolute 'path' to it. It eases the exploration of APIs that return large blobs of JSON but have terrible documentation.
go  json  textprocessing  grep  patternmatching  webdevel  debugging  troubleshooting  commandline  cli 
july 2019 by kme
GitHub - tomnomnom/gf: A wrapper around grep, to help you grep for things
gf - A wrapper around grep to avoid typing common patterns.

What? Why?

I use grep a lot. When auditing code bases, looking at the output of meg, or just generally dealing with large amounts of data. I often end up using fairly complex patterns like this one:

▶ grep -HnrE '(\$_(POST|GET|COOKIE|REQUEST|SERVER|FILES)|php://(input|stdin))' *

It's really easy to mess up when typing all of that, and it can be hard to know if you haven't got any results because there are non to find, or because you screwed up writing the pattern or chose the wrong flags.

I wrote gf to give names to the pattern and flag combinations I use all the time. So the above command becomes simply:

▶ gf php-sources
go  cli  commandline  searching  textprocessing  patternmatching  regex  grep  alternativeto  ack  ag 
july 2019 by kme
xpath - Why doesn't xmlstarlet select all nodes? - Stack Overflow |
Is this what you need?
<code class="language-bash">xml sel -t -m "//@category" -v "." -o " " books.xml</code>

or to separate the results on each line
<code class="language-bash">xml sel -t -m "//@category" -v "." -n books.xml</code>
xml  xpath  xmlstarlet  webdevel  samplecode  patternmatching 
march 2018 by kme
html - XPath with optional element in hierarchy - Stack Overflow |
My answer was to just use two piped XPath expressions. This seems to work if you have something like 'saxon-lint' that understands it, though:
In XPath 2.0, the optional step can be expressed as (tbody|.).
xpath  xpath2  patternmatching  xml  webdevel  solution 
march 2018 by kme
html - Testing text() nodes vs string values in XPath - Stack Overflow |
XPath text() = is different than XPath . =

(Matching text nodes is different than matching string values)

The following XPaths are not the same...
<code class="language-xpath">//span[text() = 'Office Hours']</code>

Says: Select the span elements that have an immediate child text node equal to 'Office Hours`.

<code class="language-xpath">//span[. = 'Office Hours']</code>

Says: Select the span elements whose string value is equal to 'Office Hours`.
xpath  xml  syntax  textcontent  thisvsthat  patternmatching  newbie  webdevel  reference  explained 
february 2018 by kme
xml - How to use XPath contains() here? - Stack Overflow |
Example from the comments

<code class="language-xpath">//ul[@class='featureList' and ./li[contains(.,'Model')]]</code>
xpath  xml  webdevel  reference  patternmatching 
february 2018 by kme
Javascript regex multiline flag doesn't work - Stack Overflow |

According to MDN, [^] also works to match any character, including newlines, in JavaScript.
javascript  regex  regexp  patternmatching  webdevel  solution 
october 2017 by kme
xpath - Pattern Matching with XSLT - Stack Overflow

Regular Expressions are supported only in XSLT 2.x/XPath 2.x.

As at this date, no publicly available browser supports XSLT 2.x/XPath 2.x.

In your concrete case you can use:


other useful XPath 1.0 functions are:








scraping  screenscraping  webscraping  xpath  xslt  xml  html  patternmatching  regex  solution 
may 2017 by kme
bash regex match string - Stack Overflow

To match regexes you need to use the =~ operator.

Try this:

[[ sed-4.2.2.tar.bz2 =~ tar.bz2$ ]] && echo matched

Alternatively, you can use wildcards (instead of regexes) with the == operator:

[[ sed-4.2.2.tar.bz2 == *tar.bz2 ]] && echo matched

If portability is not a concern, I recommend using [[ instead of [ or test as it is safer and more powerful. See What is the difference between test, [ and [[ ? for details.

See also:
bash  regex  regexp  patternmatching  newbie  dammitbrain 
december 2016 by kme
How to negate specific word in regex? - Stack Overflow
I was trying to create a DataTable filter regexp which *didn't* match something anywhere in the line. What I wasn't doing was including the ".*" WITHIN the negative lookahead expression.
regexp  javascript  fuckina  dammitbrain  solution  patternmatching 
april 2015 by kme
regex - Trim trailing spaces before newlines in a single multi-line string in JavaScript - Stack Overflow
Solution to an issue I was having where JavaScript loaded a file obtained by XHR into a textarea, but inserted a mysterious trailing newline that wasn't in the original file.
dd the 'm' multi-line modifier.

replace(/\s+$/gm, "")

Or faster still...

replace(/\s\s*$/gm, "")
webdevel  javascript  solution  patternmatching  regexp 
october 2014 by kme
My Collection of PHP Performance Benchmarks
* Use strpos in most cases where you just need to tell if a string contains (or starts with) another string:
strpos($haystack, $needle) !== false
strpos($haystack, $needle) === 0
php  webdevel  optimization  performance  stringmanipulation  patternmatching  regexp  comparison 
october 2014 by kme
Non-Greedy Regular Expression Matching - Vincent Liu
For vim, the syntax is slightly more convoluted, so it's important to put a note here for my own reminder:

* (0 or more) greedy matching
\+ (1 or more) greedy matching
\{-} (0 or more) non-greedy matching
\{-n,} (at least n) non-greedy matching
patternmatching  vim  regex  solution 
december 2013 by kme
Beyond grep: ack 2.04, a source code search tool for programmers
For Ubuntu/Debian:
sudo dpkg-divert --local --divert /usr/bin/ack --rename --add /usr/bin/ack-grep
ack  cli  devel  programming  patternmatching  perl  commandline  textprocessing  essential  utility  software 
may 2013 by kme

Copy this bookmark:

to read