How to match regexp with ash?

ash shell redirection
ash for loop
ash shell read
ash scripting
ash shell expansion
ash exec
busybox ash

Following code works for bash but now i need it for busybox ash , which apparrently does not have "=~"

keyword="^Cookie: (.*)$"
if [[ $line =~ $keyword ]]
bla bla

Is there a suitable replacement ?

Sorry if this is SuperUser question, could not decide.

Edit: There is also no grep,sed,awk etc. I need pure ash.

For this particular regex you might get away with a parameter expansion hack:

if [ "$line" = "Cookie: ${line#Cookie: }" ]; then
    echo a

Or a pattern matching notation + case hack:

case "$line" in
    "Cookie: "*)
        echo a

However those solutions are strictly less powerful than regexes because they have no real Kleene star * (only .*) and you should really get some more powerful tools (a real programming language like Python?) installed on that system or you will suffer.

RegExp testing with ash shell (BusyBox), Note that those match on each line inside $in as opposed to the content of $in as a whole. For instance, they would match on the second and third line of a $in� A regular expression enclosed in slashes (‘/’) is an awk pattern that matches every input record whose text belongs to that set. The simplest regular expression is a sequence of letters, numbers, or both. Such a regexp matches any string that contains that sequence. Thus, the regexp ‘foo’ matches any string containing ‘foo’.

Busybox comes with an expr applet which can do regex matching (anchored to the beginning of a string). If the regex matches, its return code will be 0. Example:

 # expr "abc" : "[ab]*"
 # echo $?
 # expr "abc" : "[d]*"
 # echo $?

Regex, In BusyBox ash, it's not matched by [.a] ; other shell implementations may differ. / can only be matched literally, and has higher parsing� Regards, Ash . 1093 Views Tags: aketi. Content tagged with aketi Regular expression help for matching numbers. ash0602 Aug 6, 2010 12:24 PM

What worked for me was using Busy Box's implementations for grep and wc:

MATCHES=`echo "$BRANCH" | grep -iE '^(master|release)' | wc -l`
if [ $MATCHES -eq 0 ]; then
 echo 'Not on master or release branch'

Regular Expressions, E.g. to match "1+1=2", the correct regex is 1\+1=2. Since ASH's regular expressions are directly passed to Java, ASH does not support� str.match(regexp) The method str.match(regexp) finds matches for regexp in the string str. It has 3 modes: If the regexp doesn’t have flag g, then it returns the first match as an array with capturing groups and properties index (position of the match), input (input string, equals str):

Talk:String Handling Routines, Regular expressions deal with pattern matching. Starting Group s = Matches [ a-z] Then the page explains how they can be used in ash. I DO have a habit of documenting regular expressions with at least one sentence giving the basic intent and at least one example of what would match. Because regular expressions are built up I feel it is an absolute necessity to comment on the largest components of each element in the expression.

ash test: is string A contained in string B, Since busybox uses ASH rather than BASH, some things don't work. The bash & grep solutions can narrow the match by using the regex� if [[ "my name is deepak prasad" =~ "prasad"$]]; then echo "bash regex match" else echo "bash regex nomatch" fi. Here we use =~ instead of == to match a pattern and dollar $ sign to match the last word of the string. Now since "prasad" is the last word in my name is deepak prasad hence the bash pattern match is successful.

lodash-match-pattern, Miss any of our Open RFC calls?Watch the recordings here! � lodash-match- pattern. 2.2.1 • Public • Published 25 days ago. Readme � ExploreBETA � 3� The REGEXP_MATCH function evaluates a field or expression using Google RE2 regular expression. Sample usage. REGEXP_MATCH(name, '[a-zA-Z].*') Syntax REGEXP_MATCH (X, regular_expression) Parameters. X - a field or expression to evaluate. regular_expression - a regular expression. Notes. Regular expressions in Data Studio use RE2-style syntax.

  • Wow, no POSIX. Just out of curiosity, what system are you running on?
  • Thanks this works. As you say it is very limited though. It is a router with very little space cant install perl or python. Might try C.