|
I often find this in scripts (and, I have to admit, write it myself):
a=`echo $x | sed "s/foo/bar/"`
or
if echo $x | grep foo then ... fi
Consider "foo" to include some regex stuff.
I feel that there should be - and most likely is - a better way to phrase...
Started by DevSolar on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at superuser):
Unless you assume a specific shell....
Sed 's/foo/bar/' <<< "foobie" grep 'this' <<< need it.
Fi
Where foo is a regular expression.
Fi
Consider using:
if [ $x =~ foo ] then ...
Be
Instead of:
if echo $x | grep foo then ...
|
|
Hi,
I wonder the general rule to use regular expression in if clause in bash?
Here is an example
$ gg=svm-grid-ch $ if [[ $gg == *grid* ]] ; then echo $gg; fi svm-grid-ch $ if [[ $gg == ^....grid* ]] ; then echo $gg; fi $ if [[ $gg == ....grid* ]] ; then...
Started by Tim on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Check http://tldp.org/LDP/abs represents a sequence of zero or more characters:
if [[ $gg == ????grid* ]] ; then echo $gg; fi
When using a regular expression, a dot represents....
If [[ $gg =~ ^....grid.* ]]
Use =~
for regular expression.
|
|
Hi,
We write a lot of code to htaccess but what is the best method to debug other than refreshing the page ?
Is there some way that I can write it out to a file ? or is there some echo/print function ?
Simply how do i know what my $1 $2 $3 is ?
Started by Devrim on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at serverfault):
Try these:
RewriteLog "/myfolder/mylogfile.log" RewriteLogLevel 3
These are just Regular.
|
Ask your Facebook Friends
|
Hi all :)
I'm currently writing sort of a download manager and I was asking myself if that was possible:
if($ext == ('zip' || 'png')) { echo "Is it possible ?" }
It returns true everytime, so I guess it's not possible. But do you have an idea about how...
Started by Minishlink on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
If(preg_match("/^(zip|png)$/", $ext) { echo “It is possible!” }
Related question: Checking for file-extensions in PHP with Regular expressions
You could go' echo "It is possible"; break....
You can use regular expressions, e.g.
|
|
Hi Guys ive tried to search for this answer all morning, but with no luck, all i want to do is match [slideshow or [gallery with the included [ bracket..
code as follows.
$gallery = get_post_meta($post->ID, 'gallery', true); if (preg_match("|^/[slideshow...
Started by Marty on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
("|^\[slideshow|", $gallery)
if (preg_match("/^\[slideshow/", $gallery)) { echo "Slideshow was forund"; } else if (preg_match("/^\[nggallery/", $gallery)) { echo "Gallery was found"; } else { echo "No Match.
|
|
Usually I use David Sky's "bouncing ball" effect plug-ins, but I've always been
disappointed when "extra" space is created due to wrong delay times being
entered. For instance, several seconds of silence.
To counteract this, I created this plug-in, which...
Started by loopman on
, 2 posts
by 1 people.
Answer Snippets (Read the full thread at audacityteam):
VARZ01--Prep Zero ZT ECHO (v01.0).xls documentation (203.5 KiB.
Be helpful to beginner programmers.
|
|
The PHP short tag <?= $var ?> has been deprecated for a while. Almost all PHP frameworks use the long form <?php echo $var ?> (e.g., symphony , Yii , Kohana ) Smarty is a famous PHP template engine which supports a shorter form {$var} Template...
Started by Wernight on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
In my foreach ($k as $v) { ?> <option value="<?php echo htmlentities($v['value']); ?>"><?php echo htmlentities($v['label']); ....
With it's own quirks to learn in order to accomplish the same thing with regular PHP.
|
|
Hello,
im trying to make a bash script to check if a email address is correct.
I have this regular expression:
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
Source...
Started by ballstud on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
You have several problems here:
The ....
Foo@example.com looks perfectly fine and will be accepted by any regular expression, but still it doesn't exist.
To use a simpler regular expression like .*@.* because all the complexity is futile.
|
|
I need to get "yomomedia.com" if the HTTP_HOST is [ANY].yomomedia.com except in the cases where it is "dev.yomomedia.com" else it should return dev.yomomedia.com
echo preg_replace("/^([EVERYTHING-OTHER-THAN-DEV])\./Ui","",$_SERVER['SERVER_NAME'])
Just...
Started by farinspace on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
So....
So your expression means the same as the first three characters are not dev ( ^(?!dev) ) AND the first character is a full stop ( ^\ .
A negative passive group (lookahead) should do:
/^(?!dev).*\./Ui
Look-arounds do not “consume” any characters .
|
|
I want to store part of an id, and throw out the rest. For example, I have an html element with an id of 'element-12345'. I want to throw out 'element-' and keep '12345'. How can I accomplish this?
I can capture and echo the value, like this:
| storeAttribute...
Started by Andrew on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Element-(\d+)/i
That's a regular expression that would capture the numbers after the dash | elementID | | storeEval | '${elementID}'.replace("element-", "") | myID |
Now if I echo myID I get just the ID:
| echo | ${myID} | 12345 ....
|