> Part of the fish philosophy is "it's not in fish if it's somewhere else" > > function regex_captures > perl -E '$str=shift; $re=shift; say for $str =~ /$re/' $argv > end > > Then you can do something like this: > > $ regex_captures foobar 'f(.+)b(.+)' | while read match; set matches > $matches $match; end > $ count $matches > 2 > $ for m in $matches; echo ">$m<"; end > >oo< > >ar< >
Thanks. I can't say I like that particular snippet of Perl - it just reminds me of why I don't use Perl any more - but I get the idea. "The fish way" is to define my own function using external tools, that does what I need. > On Thu, Oct 2, 2014 at 2:32 PM, Andrew Schulman <and...@utexas.edu> wrote: > > > Hi. New fish user, and first post here. > > > > What's the recommended way to do regular expression testing and matching in > > fish? The test function doesn't support regexes. I could use expr, for > > example: > > > > if expr $var : 'a(.)b(.)' > > then > > # do something with the match > > end > > > > but that's awkward, because expr will only output the result of one match, > > it sends the result to stdout, and the exit status isn't necessarily 0 on > > success - it depends on the regex. > > > > What I'd like is to have is a function or operator whose exit status tells > > me whether the regex matched, and that returns an array of the matched > > results from ()... kind of like how (sorry) bash does it. ------------------------------------------------------------------------------ Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk _______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users