Issues with expr command on Solaris Box

Hello Friends,

I have written a code on a Linux box, however, am getting issues while running it on a Solaris server. The issue with Sed command is sortd out, however, am still lokking for solutions with expr command. Here is the issue,

Linux :

 bash-2.03$ expr match singh@test.com '\(^[a-zA-Z0-9\w\.\_\-]*@[Tt][Ee][Ss][Tt].[Cc][Oo][Mm]$\)'
singh@test.com
bash-2.03$

Solaris :

bash-2.03$ expr match singh@test.com '\(^[a-zA-Z0-9\w\.\_\-]*@[Tt][Ee][Ss][Tt].[Cc][Oo][Mm]$\)'
bash-2.03$

The output in solaris is blank. Could anyone please let me know what changes can I make in this command to make it work.

Any suggestions would be greatly appreciated !!!

You may want to try one of these perhaps.

gaurav@localhost:~$ echo singh@test.com | perl -wlp -e '/^\S+\@test.com/i'
singh@test.com

Test your i/ps with this . "-i" stands for case-insensitive. so it makes your regex less ugly. code your stuffs in perl if you want them portable would be my advise.

Regards,
Gaurav.


  1. a-zA-Z0-9\w\.\_\- ↩︎

  2. a-zA-Z0-9\w\.\_\- ↩︎

Don't have a solaris but try to use the comparison operator : instead of its alias.

bash-2.03$ expr singh@test.com : '\(^[a-zA-Z0-9\w\.\_\-]*@[Tt][Ee][Ss][Tt].[Cc][Oo][Mm]$\)'

Hi Gaurav,

Thanks for the suggestion. Am not familiar with Perl Scripting, however, now I am plannig to study it as well. Could you please let me know how can I make exact pattern match, for instance singh@test.coms should not be matched. (there is an extra "s" after com).

---------- Post updated at 06:53 AM ---------- Previous update was at 06:51 AM ----------

@Ripat

That option did not worked :frowning:

Why don't you try with grep:

~$ echo 'singh@test.com' | grep -qi '^[a-z0-9_-.]\+@test\.com$' && echo 'got a match' || echo 'failed'

> got a match



$ echo 'singh@test.coms' | grep -qi '^[a-z0-9_-.]\+@test\.com$' && echo 'got match' || echo 'failed'

> failed

Hi. thats simple regex modification. put a "$" (end of line) after com. for example

gaurav@localhost:~$ echo singh@test.coms | perl -wln -e 'print if /^\S+\@test.com$/i'
gaurav@localhost:~$ echo singh@test.com | perl -wln -e 'print if /^\S+\@test.com$/i'
singh@test.com
gaurav@localhost:~$ 

Hope you get the point.
Regards,
Gaurav.

This pattern /^\S+\@test.com$/i will match anybody@testscom. Shouldn't the dot be escaped?

Hello ripat,

Indeed it should be escaped.
but that kind of input is unlikely of course.

Regards,
Gaurav.

Try this :wink:

bash-2.03$ expr match singh@test.com '\([a-zA-Z0-9\w\.\_\-]*@[Tt][Ee][Ss][Tt].[Cc][Oo][Mm]\)'
singh@test.com

Regards
ygemici

@ ygemici ... thanks for the reply ... though this will not give an exact match, see the below one

bash-2.03$ expr match singh@test.comtest '\([a-zA-Z0-9\w\.\_\-]*@[Tt][Ee][Ss][Tt].[Cc][Oo][Mm]\)'
singh@test.com
bash-2.03$

---------- Post updated at 01:15 PM ---------- Previous update was at 01:13 PM ----------

Hey Gaurav,

I guess S+ would allow only alphabets to be matched ... I need a regex which would allow a combination "-, _, ., alphabets and numerals" as input for email address.

---------- Post updated at 01:20 PM ---------- Previous update was at 01:15 PM ----------

Hey Ripat,

Am getting following error while using grep command,

bash-2.03$ echo 'singh@test.com' | grep -qi '^[a-z0-9_-.]\+@test\.com$' && echo 'got a match' || echo 'failed'
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .
failed
bash-2.03$

hello

gaurav@localhost:~$ echo singh_.@test.com | perl -wln -e 'print if /^\S+\@test.com/i'
singh_.@test.com
gaurav@localhost:~$ echo singh##___.@test.com | perl -wln -e 'print if /^\S+\@test.com/i'
singh##___.@test.com
gaurav@localhost:~$ 

\S matches any non-space characters which includes dot,@,# or any special characters.

Regards,
gaurav.