469,125 Members | 1,753 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,125 developers. It's quick & easy.

Problem with pattern matching in .sh script

Hello all,
I am doing a pattern matching for a string in a shell script.
Here an apostrophe ( ' ) is also a part of a string hence it should also be part of the pattern. But somehow i can't seem to be able to include it.
I have tried using the backslash to escape it but to no success.
Also tried putting ' inside two others like this ' ' ' .... but this doesn't work as well.
Please help.

My code look something like this :
Code: ( text )

if( $0 ~ /^"[-a-zA-Z---<> ;0-9]+"/ )
{
}
else
{
}

The string should should have ( " ) at the start and the end and in between alpha-numeric characters with some special chars.
e.g : "Mont-l'pierre"

Thanks !!
Sid
Aug 28 '07 #1
5 2924
Try Using in groups which will say something like ( ) ( ) and instead of using [A-Za-Z] try using \w+
Aug 28 '07 #2
Try Using in groups which will say something like ( ) ( ) and instead of using [A-Za-Z] try using \w+

You can use a backslash character(\) to escape the special meaning of the character ( ' ). It works.
Aug 30 '07 #3
numberwhun
3,503 Expert Mod 2GB
Hello all,
I am doing a pattern matching for a string in a shell script.
Here an apostrophe ( ' ) is also a part of a string hence it should also be part of the pattern. But somehow i can't seem to be able to include it.
I have tried using the backslash to escape it but to no success.
Also tried putting ' inside two others like this ' ' ' .... but this doesn't work as well.
Please help.

My code look something like this :
Code: ( text )

if( $0 ~ /^"[-a-zA-Z---<> ;0-9]+"/ )
{
}
else
{
}

The string should should have ( " ) at the start and the end and in between alpha-numeric characters with some special chars.
e.g : "Mont-l'pierre"

Thanks !!
Sid
Sorry, but this forum is for questions related to Perl scripting, not Shell scripting. Unless of course you have a Perl question?


Could a Moderator please move this posting to either the Linux/Unix/BSD forum or the Misc. Questions forum please? Thank you!

Regards,

Jeff
Aug 30 '07 #4
prometheuzz
197 Expert 100+
...
Could a Moderator please move this posting to either the Linux/Unix/BSD forum or the Misc. Questions forum please? Thank you!
...
Done.

.......................
Aug 30 '07 #5
Firstly sorry for posting the question in the wrong section.

And thanks everyone for your replies / suggestions.
I was facing a strange problem in that the backslash did not escape the ( ' ). Nevertheless I used the hex value of ( ' ) and then it worked.
Very strage to me and also makes the code shabby to read.

Regards,
Sep 3 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by gsv2com | last post: by
176 posts views Thread by Thomas Reichelt | last post: by
9 posts views Thread by Xah Lee | last post: by
7 posts views Thread by Niko | last post: by
5 posts views Thread by olaufr | last post: by
2 posts views Thread by ctiggerf | last post: by
2 posts views Thread by i80and | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.