Lua need to split at comma

Try this str=”cat,dog” for word in string.gmatch(str, ‘([^,]+)’) do print(word) end ‘[^,]’ means “everything but the comma, the + sign means “one or more characters”. The parenthesis create a capture (not really needed in this case).

Using match to find substrings in strings with only bash

You can use the BASH_REMATCH variable in bash to get the matched string: $ Stext=”Hallo World” $ [[ $Stext =~ ^.[a-z]* ]] && echo $BASH_REMATCH Hallo $ [[ $Stext =~ ^(.[a-z]*) ]] && echo ${BASH_REMATCH[1]} Hallo Substrings matched by parenthesized subexpressions within the regular expression are saved in the array variable BASH_REMATCH. The element of … Read more

Javascript Regexp loop all matches

I agree with Jason that it’d be faster/safer to use an existing Markdown library, but you’re looking for String.prototype.replace (also, use RegExp literals!): var Text = “[Text Example][1]\n[1][http: //www.example.com]”; var rePattern = /\[(.+?)\]\[([0-9]+)\]/gi; console.log(Text.replace(rePattern, function(match, text, urlId) { // return an appropriately-formatted link return `<a href=”https://stackoverflow.com/questions/5835418/${urlId}”>${text}</a>`; }));

Can I use ” in match?

You can use a match guard, but that feels more verbose than a plain if statement: return match delta { d if d < 0 => QuadraticResult::None, d if d > 0 => QuadraticResult::TwoRoots(0.0, 1.0), _ => QuadraticResult::OneRoot(0.0), }

Regex Group in Perl: how to capture elements into array from regex group that matches unknown number of/multiple/variable occurrences from a string?

my $string = “var1=100 var2=90 var5=hello var3=\”a, b, c\” var7=test var3=hello”; while($string =~ /(?:^|\s+)(\S+)\s*=\s*(“[^”]*”|\S*)/g) { print “<$1> => <$2>\n”; } Prints: <var1> => <100> <var2> => <90> <var5> => <hello> <var3> => <“a, b, c”> <var7> => <test> <var3> => <hello> Explanation: Last piece first: the g flag at the end means that you can … Read more